Forum Moderators: phranque
I'm rewriting seemingly static URLs onto a script to display results from a database and have the following .htaccess file:
[quote]# Redirect any pubs whose names or locations have changed
redirect 301 /pubs/loxley/robin-hood/ http://www.example.com/pubs/stannington/robin-hood/# Rewrite the area and name onto the new script to find the pub
RewriteRule ^([a-z-]+)/([a-z'0-9&\.-]+)/$ pubs.php?area=$1&name=$2 [NC,L]
[/quote]
So for example http://www.example.com/pubs/stannington/robin-hood/ is rewritten to http://www.example.com/pubs/pubs.php?area=stannington&name=robin-hood
That works fine.
Sometimes I need to change the name or area of an existing pub and so I use the 301 redirect at the top of the script. Strangely though, I noticed that the example shown gets redirected from http://www.example.com/pubs/loxley/robin-hood/ to http://www.example.com/pubs/stannington/robin-hood/?area=loxley&name=robin-hood
So it does get redirected to the correct URL, but the second part of my redirection appends the variables to the URL. Both sets of code work exactly as expected when used separately.
Any ideas why it behaves in this way?
RewriteRule ^loxley/robin-hood/$ http://www.example.com/pubs/stannington/robin-hood/ [R=301,L]
# Rewrite the area and name onto the new script to find the pub
RewriteRule ^([a-z-]+)/([a-z'0-9&\.-]+)/$ /pubs/pubs.php?area=$1&name=$2 [NC,L] [edited by: Caterham at 7:13 pm (utc) on Sep. 6, 2006]