2016-05-13 13 views
1

ich eine Liste von Umleitungen haben zu tun, und viele von ihnen sind auf andere ähnliche, aber weniger oder mehr restrictives, zum Beispiel:MEHRERE QUERY_STRING KOMBINATION ALLEIN QUERY_STRING

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

Und in auf der anderen Seite:

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

Jetzt habe ich versucht, mit:

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] 

Das Problem ist, dass irgendetwas davon geht an http://www.google.com/?code=2 oder http://www.google.com/?code=2&category=5

Haben Sie irgendwelche Vorschläge?

Vielen Dank.

Antwort

1

Falls für

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] 

Falls für

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

verwenden

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] 
1

können Sie die folgenden Regeln verwenden, um Ihre URLs zu umleiten:

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] 
0

Und andere Frage:

Wenn Sie mehr als eins mit 1 Element wie haben, und das andere ist ähnlich wie das vorherige, ist eine Möglichkeit, ohne zu sortieren, zu spezifizieren?

Nun, wenn ich zum Beispiel haben:

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] 

Es geht durchweg auf die http://www.microsoft.com weil code = enthält 234 code = 2 ....

+1

Verwenden 'RewriteCond% {QUERY_STRING} code = $ 2 'und' RewriteCond% {QUERY_STRING} code = 234 $ 'anstelle von' RewriteCond% {QUERY_STRING} ** code = 2 ** 'und' RewriteCond% {QUERY_STRING} ** code = 234 ** '. –

+0

Ich habe die Antwort aktualisiert. Überprüfen Sie bitte das. –

+0

Das nächste Mal bitte aktualisieren Sie es auf Ihre Frage oder stellen Sie eine neue Frage, anstatt als eine andere Antwort hinzuzufügen. –

Verwandte Themen