且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用 %23 重写 URL?

更新时间:2023-11-26 23:28:10

%23# 的 URL 编码表示.我怀疑您的重写规则不满足 %23.您应该调查响应是如何构建的.具体来说,任何 URL 编码函数.

%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.

# http://example.org/foo-bar/%23comment-570630 -> http://example.org/foo-bar/#comment-570630
RewriteCond %{REQUEST_URI} %23comment-d+$
RewriteRule (.+)/%23-comment(d+)$ http://host/$1/#comment-$2 [R=301]

它未经测试,但应该可以工作(我不确定是否转义 \% 因为它在 mod_rewrite 中具有特殊含义).

It's untested, but should work (I'm unsure about escaping \% as it has special meaning in mod_rewrite).