mod_rewrite RewriteRule 处理 HTML 实体
由于某种原因,我们在包含 HTML 实体的 URL 上收到大量入站流量。
例如
http://www.ourdomain.com/index.php?key1=value1&key2=value2
我想创建一个 RewriteRule 来替换这些 HTML 实体(特别是 & 与 & ;),并将人们转发到更正的地址。
我尝试过这些:
RewriteRule & & [R=permanent]
和
RewriteRule & &
但什么也没发生。
(顺便说一句。我知道这是解决别人问题的一种可怕且危险的方式,但我只需要暂时完成它)
感谢您的帮助...
For some reason, we recieving a bunch of inbound traffic on URLs that contain HTML entities.
E.g.
http://www.ourdomain.com/index.php?key1=value1&key2=value2
I want to create a RewriteRule to replace these HTML entities (specifically & with &), and forward people on to the corrected address.
I'm tried these:
RewriteRule & & [R=permanent]
and
RewriteRule & &
But nothing is happening.
(BTW. I know this is a horrible and dangerous way to solve someone else's problem, but I just need to get it done. temporarily)
Thanks for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以解决问题;
这实质上是说;
&
?&
将它们夹在一起。N
标志实际上表示“继续执行此操作,直到条件不再满足”匹配'查看 mod_rewrite 文档,包括 RewriteCond 和 规则标志。
This should do the trick;
This essentially says;
&
in the query string?&
N
flag in the rule effectively says 'keep doing this until the condition no longer makes a match'Check out the mod_rewrite documentation, including RewriteCond and rule flags.
为了使任何重写工作,重写引擎必须打开,但也许您已经修复了这个问题:
& 符号是一个特殊的元字符。显然,复制并粘贴您的链接的人是在编辑器中进行了此操作,该编辑器适当地将&符号转义为
&
(或者,从技术上讲更正确的是,&
) code> 如果它发生在 a 标签内)。我不是 100% 确定,但我发现 & 符号应该被转义,试试这个:要了解重写如何进行、重写什么以及为什么,您应该打开重写日志记录(确保 Apache 可以写入
RewriteLog
的位置):其中级别 9 是最高的。
For any rewrite to work, the rewrite engine must be on, but perhaps you already have that fixed:
The ampersand is a special metacharacter. Apparently the people that have copied and pasted your links did so inside an editor which duely escaped the ampersands into
&
(or, more technically correct,&
if it happened inside an a-tag). I'm not 100% sure, but I find it likely that the ampersand should be escaped, try this:To find out how the rewrite goes, what it rewrites and why, you should turn rewrite logging on (make sure Apache can write to the location of
RewriteLog
):where level 9 is the highest.