Apache mod_rewrite 替换 REQUEST_URI 中的字符
我正在尝试编写一些 .htaccess 规则来替换 REQUEST_URI 参数中的某些字符。具体来说,我想替换以下内容:
- “<” =
<
- “>” =
>
- "'" =
'
- '"' =
"
- ")" =
)
- "(" =
(
示例 URL 可以是 http://www.example.com/?&q=")("
我尝试了一大堆方法但没有成功,有人能指出我正确的方向吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 mod_rewrite 来执行此替换,请参阅
<
示例:第一个规则将一次替换两个
<
字符,第二个规则将结束递归。其他字符可以用相同的方式替换(只需将<
和<
替换为其他对)。但是使用 mod_rewrite 来完成此类工作不太合适,因为
尽管由于使用了 在这种情况下第二条语句不适用N 标志,我不建议在此类工作中使用 mod_rewrite。
我宁愿建议在 Web 应用程序中执行此操作,可能是在将数据放入 HTML 文档之前,而不是对每个输入都采取预防性的方式,无论数据是如何处理的。
You can use mod_rewrite to do this replacement, see this example for
<
:The first rule will replace two
<
characters at a time and the second will end the recursion. The other characters can be replaced in the same way (just replace<
and<
with the other pairs).But using mod_rewrite for this kind of work is not that suitable because
Although the second statement does not apply in this case due to the usage of the N flag, I would not recommend the usage of mod_rewrite for this kind of work.
I would rather recommend to do this in the web application, possibly just before putting your data out into an HTML document and not in a prophylactic manner for every input no matter how that data is processed.