开发者

how to redirect request based wether a query string value is present?

开发者 https://www.devze.com 2023-01-12 07:17 出处:网络
I\'ve searched and tried many examples but none seem to work for me. I need to redirect a request to a specific url depending on if the original request had a certain item in it\'s query string.

I've searched and tried many examples but none seem to work for me. I need to redirect a request to a specific url depending on if the original request had a certain item in it's query string.

e.g.

www.mydomain.com/test.html?username=foo&password=bar

So I want to redirect this only is the username variable is present in the query string to

www.mydomain.com/home.html?username=foo&password=bar

But also, the page could be any page, .e.g test.html, home.html, contact.php

So if username variable is 开发者_JS百科detected in query string, then the redirect will happen only.

thanks for your help.

I tried this but it did not work:

RewriteRule ^username(.*)$ test.html?username=$1 [L,QSA]


You can use QUERY_STRING to accomplish this.

RewriteCond %{QUERY_STRING} username
RewriteCond %{REQUEST_URI} !^/home.html
RewriteRule .* /home.html/ [L,QSA]
0

精彩评论

暂无评论...
验证码 换一张
取 消