1

I've a list of redirections to do and many of them are similar to others, but less or more restrictives, for example:

http://www.example.com/example/form.aspx?code=2 to http://www.google.com

And in the other hand:

http://www.example.com/form.aspx?category=5&code=2 to http://www.microsoft.com

Now i tried with:

RewriteCond %{QUERY_STRING} ^code=2$
RewriteCond %{REQUEST_URI} "^/example/form(.*)"
RewriteRule (.*) http://www.google.com? [R=301,L]

RewriteCond %{QUERY_STRING} code=2
RewriteCond %{QUERY_STRING} category=5
RewriteCond %{REQUEST_URI} "^/example/form(.*)"
RewriteRule (.*) http://www.microsoft.com? [R=301,L]

The problem is that any of that goes to http://www.google.com/?code=2 or http://www.google.com/?code=2&category=5

Have you any suggestions?

Thanks you.

3 Answers 3

1

In case for

http://www.example.com/example/form.aspx?code=2 --> http://www.google.com

http://www.example.com/form.aspx?category=5&code=2 --> http://www.microsoft.com

RewriteCond %{QUERY_STRING} ^code=2$
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.google.com? [R=301,L]

RewriteCond %{QUERY_STRING} code=2$
RewriteCond %{QUERY_STRING} ^category=5
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.microsoft.com? [R=301,L]

In case for

http://www.example.com/example/form.aspx?category=5&code=2 --> http://www.microsoft.com

http://www.example.com/example/form.aspx?category=5&code=234 --> http://www.stackoverflow.com

Use this

RewriteCond %{QUERY_STRING} code=2$
RewriteCond %{QUERY_STRING} ^category=5
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.microsoft.com? [R=301,L]

RewriteCond %{QUERY_STRING} code=234$
RewriteCond %{QUERY_STRING} ^category=5
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.stackoverflow.com? [R=301,L]
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the following rules to redirect your urls :

RewriteCond %{THE_REQUEST} /example/form\.aspx\?code=2 [NC]
RewriteRule ^ http://google.com/? [L,R]
RewriteCond %{THE_REQUEST} /example/form\.aspx\?category=5&code=2 [NC]
RewriteRule ^ http://microsoft.com/? [L,R]

Comments

0

And any other question:

if you have more than one with 1 element like, and the other is similar to the previous, is any way to specify without need to sort?

Now if i have for example:

RewriteCond %{QUERY_STRING} **code=2**
RewriteCond %{QUERY_STRING} category=5
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.microsoft.com? [R=301,L]

RewriteCond %{QUERY_STRING} **code=234**
RewriteCond %{QUERY_STRING} category=5
RewriteCond %{REQUEST_URI} ^/example/form(.*)
RewriteRule ^(.*)$ http://www.stackoverflow.com? [R=301,L]

It goes allways to the http://www.microsoft.com because code=234 contains code=2....

2 Comments

Use RewriteCond %{QUERY_STRING} code=2$ and RewriteCond %{QUERY_STRING} code=234$ instead of RewriteCond %{QUERY_STRING} **code=2** and RewriteCond %{QUERY_STRING} **code=234** respectively.
Next time please update it to your question or ask a new question instead of adding as another answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.