[英]mod_rewrite rule to prevent query string
好吧,我正在测试我的个人网络服务器上安装的cms(joomla),然后再投入使用。 而且我希望能够阻止查询字符串的使用,或者更多的是防止用户在查询字符串上输入内容(更改像articleid等),但仍允许内部重定向使用查询字符串。
示例阻止某人作为网址进入
http://www.doamin.com/index.php?option=com_user&view=register
显示错误页面或重定向到index.php没有查询字符串
但仍然允许重写规则
RewriteRule ^注册$ index.php?option = com_user&view = register
RewriteCond%{QUERY_STRING}!^ $
RewriteRule ^ index.php $ index.php? [R = 301]显然重定向所有查询字符串(但它也重定向/注册,这不是我想要的)
寄存器重写结束时的[L]标志也不会使规则处理停止。
编辑:结束了丹尼尔的推动回答这个问题。 见下面的答案
如果要删除现有查询字符串,请仅使用问号结束替换字符串。
虽然在这句话中没有提到,但重写规则不得使用QSA
标志。
至于仍然允许重写规则:
RewriteRule ^Register$ index.php?option=com_user&view=register
您可能希望它出现在重写规则下面以去除查询字符串。 匹配时, %{ENV:REDIRECT_STATUS}
变量设置为200,mod_rewrite再次运行重写规则。 如果未使用%{ENV:REDIRECT_STATUS}
不是200的检查,则剥离查询字符串的重写规则将匹配此第二遍。
这会将index.php
所有请求(带或不带查询字符串)映射到没有查询字符串的index.php
,但仍然允许/Register
被视为/index.php?option=com_user&view=register
:
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteRule ^index.php$ index.php?
RewriteRule ^Register$ index.php?option=com_user&view=register
或者,如果您希望在index.php
请求具有查询字符串时重定向到错误页面:
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^index.php$ error.php? [R,L]
RewriteRule ^Register$ index.php?option=com_user&view=register
但我只想使用F
标志:
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^index.php$ - [F,L]
RewriteRule ^Register$ index.php?option=com_user&view=register
好吧,虽然Daniels的回答没有完全奏效,但它让我开始走上正轨。
最终需要两个部分来做我想要的,其中一部分是使用REDIRECT_STATUS变量
首先需要
RewriteCond %{QUERY_STRING} !=""<br>
RewriteCond %{ENV:REDIRECT_STATUS} 200<Br>
RewriteRule .* - [L]<br>
.....
我所有的内部重定向
喜欢: RewriteRule ^Register$ index.php?option=com_register&view=register [L]
.....
最后
RewriteRule .* - [F,L]
使它成为唯一能够使用的东西是内部重定向定义的URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.