Trouble redirecting EZ-page to blog page via .htacess
I've added a Wordpress blog to my ZC site, in a /blog folder, which is working fine.
I've moved some of my EZ-pages to the blog, since they don't really belong on the home page.
Some of these pages were getting google traffic, which I'm trying to redirect (301) to the blog page, but I can't get this working. I'm trying to do this in .htaccess as follows:
Quote:
Redirect 301 /index.php?main_page=page&id=25 /blog/table-tennis-rules/
I've tried the above, I've also tried to redirect to the full domain, or without the trailing "/", but it never works properly. Problem is:
- when it does redirect, it does a 302 instead of a 301
- it seems to re-direct multiple (other) EZ-pages also to the same destination
- it adds a trailing "main_page=page&id=25" to the end of the destination URL
I suspect it's getting screwed up with some of the characters in the source domain, or perhaps it does not like being redirected to what looks like a folder in stead of a file. I can't figure it out!
Can someone advise me how to do this please, it would be a great help!
Thanks a lot!
Re: Trouble redirecting EZ-page to blog page via .htacess
First would be not yet to do a 301 but instead a 302 until the solution is satisfactorily found. This prevents a browser from caching the redirect as permanent instead of temporary.
Next is to identify what all is in your htaccess including the current sequence of the commands.
In the interim you may want to be sure that you are clearing your cache (and maybe cookies) on the browser that you're using between attempts at least.
Re: Trouble redirecting EZ-page to blog page via .htacess
Quote:
Originally Posted by
mc12345678
First would be not yet to do a 301 but instead a 302 until the solution is satisfactorily found. This prevents a browser from caching the redirect as permanent instead of temporary.
Next is to identify what all is in your htaccess including the current sequence of the commands.
In the interim you may want to be sure that you are clearing your cache (and maybe cookies) on the browser that you're using between attempts at least.
hey mate,
i'm going to take you up on that beer when down under!
@mc,
#1 - i do not think the doing a 302 here is at all necessary. the op has stated that they are already getting a 302, so not sure what is the point of changing the htaccess rule.
#2 - as mc has stated, i would post the complete contents of you .htaccess file. i am NOT the apache redirect expert, but it looks to be 1 of 2 choices, a.) there is another rule that is redirecting prior to hitting your rule. b.) your redirect rule is not working/getting ignored because it is not properly constructed or the .htaccess is in the wrong place. i'm betting with option b. my reasoning is simple... if one were to go to your site, the redirect is the same for both of these URLs:
/index.php?main_page=page&id=25
/index.php?main_page=page&id=2545665
which indicates to me the redirect is happening with ZC and not with your htaccess rule.
#3 - definitely not a browser cache/cookie problem.
good luck.
Re: Trouble redirecting EZ-page to blog page via .htacess
You could also edit the /includes/modules/pages/page/header_php.php and add some PHP code to do the redirect.
Something akin to this human-language description:
if (the page number is 25) {
... run the PHP statement: header('Location: /blog/whatever-page-name');
}
Re: Trouble redirecting EZ-page to blog page via .htacess
As for the redirect "issue" of the parameter remaining in the new/redirected url, the htaccess command "Redirect" does not strip the parameter from the url. Therefore to remove it via htaccess, would be better to use "RewriteRule" which also can be written to only redirect id=25 and not include any other page that starts with 25.
Code:
RewriteRule ^index\.php?main_page=page&id=25$ /blog/table-tennis-rules? [L, R=301]
As to temporarily using 302 versus 301, imagine this. An attempt to redirect is entered. A customer goes to the original address. The attempt fails because it was wrong. The customer's browser has been told that the address attempted has been permanently moved to some other non-existent location via cache. How do you tell them to clear their cache? Did your heaers include anything that would pull a new reference/location after some set time out? Does their browser support such a request?
All because wanted to test something...
It's akin to testing that the SSL certificate has been properly installed before changing a site to https and then finding out that it wasn't properly installed and shouldn't have been activated (yet). Why do something as a self test that has to be undone by others when it is possible to temporarily test and then when successful, "lock" it in.
Re: Trouble redirecting EZ-page to blog page via .htacess
Thanks for your time guys, really appreciate it!
Quote:
Originally Posted by
mc12345678
Code:
RewriteRule ^index\.php?main_page=page&id=25$ /blog/table-tennis-rules? [L, R=301]
That causes an internal server error.
Here is the rest of my .htaccess
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^tibhar\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.tibhar\.com\.au$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/tabletennisshop\.com\.au\/index\.php\?main_page\=page\&id\=44" [R=301,L]
RewriteCond %{HTTP_HOST} ^xiom\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xiom\.com\.au$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/tabletennisshop\.com\.au\/index\.php\?main_page\=page\&id\=51" [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The existing code refers to two domains (xiom and tibhar) being redirected to a specific page on the site (done through cpanel, looks messy I know), and the last bit redirects http to https.
Re: Trouble redirecting EZ-page to blog page via .htacess
So where in that htaccess was the RewriteRule inserted/tested?
Would advise that since it appears (haven't fully inspected the provided htaccess) desirable to have all domains use https that the RewriteRules direct to https: instead of http: so that there are fewer redirects when accessing that/those uris.
Re: Trouble redirecting EZ-page to blog page via .htacess
I've tried inserting it at the top, and at the bottom, results are the same.
Yes you're right about the other re-directions, they should go right to https. I'm a bit nervous to touch them as they're currently working, and I know very little about this stuff.
Re: Trouble redirecting EZ-page to blog page via .htacess
@ttfan,
i am NOT good at apache redirects. but i am willing to try.
that said, i do not agree with some of the logic going on in this thread. while this could be accomplished from within the ZC core, i am not a fan of doing it that way as it creates more work at upgrade time.
with regards to your htaccess, i would remove the 2nd instance of:
there is no need for it.
in addition, there are 2 problems (that i can see) with regards to mc's rewrite rule. when i tested it, i was also able to reproduce the internal server error. assuming our servers are similarly configured, i think the space in-between the L and the R=301 is what is causing that error. if you remove that space (similar to your other htaccess directives that are working), then the internal server error disappears.
please test that for yourself.
the second problem with that rewrite rule is it does not work. there is something going on with the parameters section of the requesting url that prevents it from matching the rule. i'm still trying to figure it out for myself.
this is a good tool here:
http://htaccess.mwl.be/
i'll keep you posted if i figure anything else out.
best.
Re: Trouble redirecting EZ-page to blog page via .htacess
try this after rewrite engine on:
Code:
RewriteCond %{QUERY_STRING} main_page=page&id=25
RewriteRule ^index\.php$ /blog/table-tennis-rules? [L,R=301]
best.