如果htaccess的重定向查询字符串变量present [英] htaccess Redirect if query string variable present

查看:159
本文介绍了如果htaccess的重定向查询字符串变量present的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加样式= 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]

这篇关于如果htaccess的重定向查询字符串变量present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆