htaccess redirect with query string

谁说胖子不能爱 提交于 2019-12-25 04:49:35

问题


I've url with a link parameter in it. I want redirect this to a php file. How can I implement this using htaccess file?

Source url: www.example.com/?id=15&L=1&link=androidapp

Target url: www.example.com/test.php

I want to check if "link=androidapp" exists, then redirect to the php file.

I've tried the following code, but not working;

RewriteCond %{QUERY_STRING} ^link=androidapp$ 
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]

Can you guys please help me to solve the problem? Thanks.


回答1:


It should work if you skip the ^ and the $ like this:

RewriteCond %{QUERY_STRING} link=androidapp 
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]

The ^ means that the your pattern matches only from the beginning of the querystring, but your querystring begins with id=15...




回答2:


Use this:

RewriteCond %{QUERY_STRING} link=androidapp(&|$) 
RewriteRule ^ http://www.example.com/test.php? [R=301,L]


来源:https://stackoverflow.com/questions/28362672/htaccess-redirect-with-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!