Forum Moderators: phranque
I have a situation where my rules are confilcting creating rather strange results.
I have:
redirect 301 /broadband/AOL+broadband/AOL+Gold http://www.example.co.uk/broadband/AOL+broadband/6
to redirect any old pages to new permanent links
and then:
RewriteRule ^broadband/(.[^/]*)/{0,1}$ /providers.html?name=$1
which is the nice looking URL rule
However if I enter the URL
http://www.example.co.uk/broadband/AOL+broadband/AOL+Gold
I get
http://www.example.co.uk/broadband/AOL+broadband/6?id=AOL+Gold
in the browser
when I want
http://www.example.co.uk/broadband/AOL+broadband/6
If you could help it would stop me going insane
Thanks
Andy
[edited by: jdMorgan at 12:05 am (utc) on Feb. 17, 2006]
[edit reason] Example.com. Please see TOS & charter. [/edit]
Welcome to WebmasterWorld!
Don't mix mod_alias and mod_rewrite redirects -- You will have no control over their order of execution. Also, both directives will be applied if the URL-prefix or URL-pattern matches.
I'd suggest you re-code your Redirect directive as a RewriteRule, and use the [L] flag on it.
Jim
However I have tried the following and it still does not work:
RewriteRule ^broadband/AOL+broadband/AOL+Gold$ http://www.example.co.uk/broadband/AOL+broadband/6 [R=301]
RewriteRule ^broadband/(.[^/]*)/(.[^/]*)/{0,1}$ /products.html?id=$2
What I would expect is the first rule to drive the input to the second rule. I couldn't include your [L] flag because I need it to continue to the next rule.
What I actually get is a 404. My rewrite_log is empty so no clues there.
Andy
[edited by: jdMorgan at 6:48 am (utc) on Feb. 17, 2006]
[edit reason] Examplified. [/edit]
You want the old->new URL external redirect to take place first. Then the browser asks for the new URL in a new HTTP transaction, which the second rule will then catch and rewrite silently to your products.html page.
Use the [L] flag unless you have proven cause not to. On both rules. Also, you need to escape any characters in your patterns that are used as regex tokens, such as "+" meaning "one or more of the preceding character, character-set, or grouped subpattern."
# External redirect
RewriteRule ^broadband/AOL\+broadband/AOL\+Gold$ http://www.example.co.uk/broadband/AOL+broadband/6 [R=301,L]
# Internal rewrite
RewriteRule ^broadband/([^/]+)/([^/]+)/?$ /products.html?id=$2 [L]
Jim