Forum Moderators: phranque

Message Too Old, No Replies

Strange, simple rewrite not working

Similar rules, only one works

         

globex

8:22 am on Nov 17, 2009 (gmt 0)

10+ Year Member



I'm having a real hard time figuring out Rewrite Rules. Hope somebody can help. Here's the issue:

==================
RewriteEngine on
Options +FollowSymlinks

# Rule 1
RewriteRule ^(.*)(gr¦gmail¦gcal¦greader)$ products/gr [QSA,L]

# Rule 2
RewriteRule ^(.*)gr/update.rdf$ http://www.example.com/products/gr/extension/update.rdf [QSA,L]

# Rule 3
RewriteRule ^(.*)gr/?page=changelog$ http://www.example.com/products/gr/?page=changelogs [QSA,L]
==================

Rule 1 redirects correctly.
Rule 2 redirects correctly.
Rule 3 redirects to products/gr

Why would rule 3 not work?

Thank you.

[edited by: jdMorgan at 1:34 pm (utc) on Nov. 17, 2009]
[edit reason] example.com [/edit]

globex

8:32 am on Nov 17, 2009 (gmt 0)

10+ Year Member



I figured it out. It was the (.*) that was messing things up.

g1smd

9:51 am on Nov 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rule 1 is a Rewrite, not a Redirect... so there is either a problem with your terminology or with the code.

If it is supposed to be a rewrite it needs to be listed after the redirects. If it is instead meant to be a redirect, you need to add FQDN and R=301 to it.

If it is a rewrite, then it is very dangerous as it maps an infinite number of duplicate URLs to one internal filepath. Even without the (.*) it would still map a very large number.

QSA is the default action, so does not need to be stated on either of the first two rules. You only need QSA when you want to re-append the original query string data on the end of new query string data.

Your last two rules produce a 302 redirect. I suspect that you will want a 301 redirect.

Rule 3 can NEVER work. RewriteRule cannot see Query Strings. You need a preceding RewriteCond to test %{QUERY_STRING}.