Can you help me with .htaccess and 301 redirects?
July 2, 2008 5:31 AM
I have a rewritecond which hands my seo friendly urls however im also trying to redirect some old pages to the new urls but the rewrite condition is screwing up the 301 redirect.
my htaccess is
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]*) pagehandler.php?string=$1 [L]
Redirect 301 /view/facilities http://www.mysite.com/facilities
what is happening is if go to
http://www.mysite.com/view/facilities
im redirected to
http://www.mysite.com/facilities?string=view
rather than
http://www.mysite.com/facilities
hi thanks for the reply
even with the 301 redirects first it still does the same thing
posted by toocan at 6:23 AM on July 2, 2008
even with the 301 redirects first it still does the same thing
posted by toocan at 6:23 AM on July 2, 2008
I think mod_rewrite directives are always processed before mod_alias, so the order won't make any difference. If you switch the Redirect to another RewriteRule (which can happily do redirects) then you should be able to control the order and get it to work.
posted by malevolent at 7:19 AM on July 2, 2008
posted by malevolent at 7:19 AM on July 2, 2008
Something like
RewriteRule ^view/facilities$ http://www.mysite.com/facilities [R=301,L]
should do the trick if placed before the other rule, unless I'm misunderstanding what you're trying to do.
posted by malevolent at 8:39 AM on July 2, 2008
RewriteRule ^view/facilities$ http://www.mysite.com/facilities [R=301,L]
should do the trick if placed before the other rule, unless I'm misunderstanding what you're trying to do.
posted by malevolent at 8:39 AM on July 2, 2008
thanks that worked a treat. how would i do it if my old url contains querystring paramaters and my new url doesnt need them ?
posted by toocan at 9:28 AM on July 2, 2008
posted by toocan at 9:28 AM on July 2, 2008
malevolent: Cool, I didn't realize that (I use mod_rewrite for everything so it hadn't occurred to me).
posted by nev at 9:42 AM on July 2, 2008
posted by nev at 9:42 AM on July 2, 2008
To remove any query string parameters I think you stick ? on the end of the destination URL, e.g.
RewriteRule ^view/facilities$ http://www.mysite.com/facilities? [R=301,L]
posted by malevolent at 12:27 PM on July 2, 2008
RewriteRule ^view/facilities$ http://www.mysite.com/facilities? [R=301,L]
posted by malevolent at 12:27 PM on July 2, 2008
« Older Recommend easy-to-use software for elderly people | Which Shape of Pasta is the Cheapest? Newer »
This thread is closed to new comments.
posted by nev at 6:05 AM on July 2, 2008