Can you help me with .htaccess and 301 redirects?
July 2, 2008 5:31 AM   Subscribe

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
posted by toocan to Computers & Internet (8 answers total) 1 user marked this as a favorite
 
Order matters, so put the /view/facilities redirect first.
posted by nev at 6:05 AM on July 2, 2008


Response by poster: 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


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


Response by poster: hi any suggestions on the rewriterule ?
posted by toocan at 8:22 AM on July 2, 2008


Best answer: 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


Response by poster: 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


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


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


« Older Recommend easy-to-use software for elderly people   |   Which Shape of Pasta is the Cheapest? Newer »
This thread is closed to new comments.