如果htaccess的重定向查询字符串变量present字符串、变量、重定向、htaccess

2023-09-02 09:53:31 作者:江上挽风吟

我需要添加样式= 2 到一个目录只有当URL不已经包含之内的所有网址样式= 2

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?

推荐答案

更​​改code本,使其工作:

Change your code to this to make it work:

RewriteCond %{QUERY_STRING} !(^|&)style=2(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?style=2 [R=301,L,QSA]