Forum Moderators: phranque

Message Too Old, No Replies

testing RewriteCond %{QUERY STRING} for multiple values

I have a URL I am trying to Rewrite by testing the value of the Argument

         

EricZ

7:27 pm on Nov 8, 2010 (gmt 0)

10+ Year Member



I see alot of examples on how to get the value of RewriteCond %{QUERY_STRING} ARG=VAL but I what I have is a URL that looks like this:

www.mysite.com/page.phtml?dogs+labrador

Since I am not setting a name=val, I am having a hard time trying to get the redirect working:

What I would like to do is to check what VAL1 is and then base a redirect on the result. Also, how would it look if I wanted to test both variables as well?

This is my feeble attempt thus far:

RewriteCond %{QUERY_STRING} ^dogs(.*)$
RewriteRule ^page\.phtml$ www.mysite.com/dogs%20page [R=301,L]

g1smd

7:54 pm on Nov 8, 2010 (gmt 0)

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



Test THE_REQUEST instead, as it records both the path and query string.

Divide it up capturing backreference $1 using everything between '?' and '+', and $2 using everything after the '+'.

EricZ

9:22 pm on Nov 8, 2010 (gmt 0)

10+ Year Member



sorry, I am not as capable with regex and mod-rewrite as I should be, I don't understand how to accomplish this, even though I know the principle of what you are doing.

jdMorgan

1:04 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code looks close to correct. Try:

RewriteCond %{QUERY_STRING} ^dogs\+(.+)$
RewriteRule ^page\.phtml$ http://www.example.com/dogs-page [R=301,L]

Note that I changed the space in the new URL to a hyphen. Unless you want to suffer for years and years, I suggest that you retain that change, and avoid the use of spaces (and upper- or mixed-case characters) in URLs.

Jim