需要在 .htaccess 重写规则中转义 # (hash/pound) 字符 [英] need to escape # (hash/pound) character in .htaccess rewrite rule

查看:43
本文介绍了需要在 .htaccess 重写规则中转义 # (hash/pound) 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题相当简单,但我已经好几个小时找不到答案了.

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

我需要做的是:

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

这基本上意味着我想对来自外部代码块的该死的哈希符号进行 url 转义.

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.

(%23 不匹配 # 因为它根本不是 == %23)

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

推荐答案

URL 的哈希部分不可重写.当 Web 浏览器向 Web 服务器发送 URL 请求时,它会将所有内容发送到井号.哈希值仅在客户端可用(例如 JavaScript 代码可以看到它).

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

这篇关于需要在 .htaccess 重写规则中转义 # (hash/pound) 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆