需要转义#(哈希/磅)字符在.htaccess重写规则重写、字符、规则、哈希

2023-09-02 09:49:20 作者:い不靠譜︶青年

现在的问题是相当简单的,但我没能找到几个小时的答案了。

The question is fairly simple but I was not able to find an answer for hours now.

我需要做的是:

RewriteRule ([^#])#(.*) $1%23$2

这基本上意味着我要URL转义的再用井号里面说到我从外部codepiece。

Which basically means I want to url escape the freaking hash sign which comes to me from an external codepiece.

反斜线( )不起作用摆脱这种迹象......请不要建议使用 23%而不是,因为它不正常工作。

backslash () does not work to escape this sign... and please don't suggest using %23 instead # because it does not work as well.

%2 3不匹配,因为它根本就没有 = =%23

(%23 does not match a # because it simply is not == %23)

推荐答案

一个URL的哈希部分不适用于重写。当Web浏览器发送一个URL请求到web服务器将其发送之前的所有内容的散列标志。哈希是唯一可用的客户端(如JavaScript的code可以看到它)。

The hash part of a URL is not available for rewriting. When a web browser sends a URL request to a web server it sends everything up to the hash sign. The hash is only available on the client (e.g. JavaScript code can see it).