htaccess 使用查询字符串重定向
htaccess redirect with query string
我 url 中有一个 link 参数。我想将其重定向到 php 文件。
我如何使用 htaccess 文件实现它?
Source url: www.example.com/?id=15&L=1&link=androidapp
Target url: www.example.com/test.php
我想检查 "link=androidapp" 是否存在,然后重定向到 php 文件。
我试过以下代码,但没有用;
RewriteCond %{QUERY_STRING} ^link=androidapp$
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]
你们能帮我解决这个问题吗?
谢谢
如果您像这样跳过 ^
和 $
,它应该可以工作:
RewriteCond %{QUERY_STRING} link=androidapp
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]
^
表示您的模式仅从查询字符串的开头开始匹配,但您的查询字符串以 id=15...
开头
使用这个:
RewriteCond %{QUERY_STRING} link=androidapp(&|$)
RewriteRule ^ http://www.example.com/test.php? [R=301,L]
我 url 中有一个 link 参数。我想将其重定向到 php 文件。 我如何使用 htaccess 文件实现它?
Source url: www.example.com/?id=15&L=1&link=androidapp
Target url: www.example.com/test.php
我想检查 "link=androidapp" 是否存在,然后重定向到 php 文件。
我试过以下代码,但没有用;
RewriteCond %{QUERY_STRING} ^link=androidapp$
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]
你们能帮我解决这个问题吗? 谢谢
如果您像这样跳过 ^
和 $
,它应该可以工作:
RewriteCond %{QUERY_STRING} link=androidapp
RewriteRule ^(.*)$ http://www.example.com/test.php? [R=301,L]
^
表示您的模式仅从查询字符串的开头开始匹配,但您的查询字符串以 id=15...
使用这个:
RewriteCond %{QUERY_STRING} link=androidapp(&|$)
RewriteRule ^ http://www.example.com/test.php? [R=301,L]