如何重写包含 %23 的 URL?
我有一个(wordpress)博客,在发表评论后,用户将被重定向回带有评论锚点的页面。应如下所示:
http://example.org/foo-bar/#comment-570630< /a>
但不知何故,我在此类 URL 的日志文件中收到了很多 404:
http:// example.org/foo-bar/%23comment-570630
有没有办法编写 .htaccess 重写规则来解决这个问题?
奖金问题: 知道为什么会发生这种情况以及我能做些什么吗?
I have a (wordpress) blog where after commenting the users are redirected back to the page with an anchor to their comment. Should look like this:
http://example.org/foo-bar/#comment-570630
But somehow I get a lot of 404 ins my logfiles for such URLs:
http://example.org/foo-bar/%23comment-570630
Is there a way to write a .htaccess rewrite rule to fix this?
Bonus question:
Any idea why this happens and what I can do about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
%23
是#
的 URL 编码表示形式。我怀疑你的重写规则不满足%23
。您应该调查响应是如何构建的。具体来说,任何 URL 编码函数。但是,可以通过重写规则来解决您的问题。请注意,提交评论后您将向客户返回两个回复。这就是为什么最好纠正第一个响应。
它未经测试,但应该可以工作(我不确定是否转义
\%
因为它在 mod_rewrite 中具有特殊含义)。%23
is the URL encoded representation of#
. I suspect your rewrite rules will not satisfy%23
. You ought to investigate how the response is being constructed. Specifically, any URL encoding functions.However, it would be possible to solve your issue with a rewrite rule. Understand that you'll be returning two responses to the client after a comment is submitted. This is why it is preferable to correct the first response.
It's untested, but should work (I'm unsure about escaping
\%
as it has special meaning in mod_rewrite).您是否尝试过 B 标志?
未经您的具体案例测试,但用于相关问题。
Have you tried the B Flag?
untested with your specific case, but used for a related problem.