如果存在查询字符串变量,则 htaccess 重定向 [英] htaccess Redirect if query string variable present
本文介绍了如果存在查询字符串变量,则 htaccess 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅当 url 尚未包含 style=2
时,我才需要将 style=2
添加到目录中的所有 url.
I need to add style=2
to all urls within a directory ONLY if the url does NOT already contain style=2
.
在根目录中,我有一个 .htaccess 文件,内容如下:
Within the directory root, I have an .htaccess with the following:
RewriteCond %{QUERY_STRING} !(?style=|&style=)
RewriteRule ^(.*)$ %1&style=2? [R=301,QSA]
我知道这是错误的.有人可以帮忙吗?
I know it's wrong. Can anyone help?
推荐答案
将您的代码更改为以下内容以使其工作:
Change your code to this to make it work:
RewriteCond %{QUERY_STRING} !(^|&)style=2(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?style=2 [R=301,L,QSA]
这篇关于如果存在查询字符串变量,则 htaccess 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文