我有一个 PHP 项目,需要在 URL 路径中发送哈希字符 (#)。 (http://www.example.com/parameter#23/parameter#67/index.php http://www.example.com/parameter#23/parameter#67/index.php)我认为 urlencode 允许这样做,将哈希值转换为 %23
但现在我发现,即使是 urlencoded 哈希也会强制浏览器将右侧的所有内容视为 URL 片段(或查询)。
有没有办法传递哈希值,或者我是否需要在 urlencode 之前进行字符替换?
编辑添加(2017 年 9 月 19 日):
事实证明我问错了问题。我的问题不在于在路径中使用哈希字符(对其进行编码确实有效),而是使用 mod_rewrite 将其转换为查询字符串。我未能在 RewriteRule 中重新编码它。我将编辑标题以匹配。
这是我使用的重写规则:
RewriteEngine On
# convert path strings into query strings
RewriteRule "^(.*)/(.*)/hashtags.php" /hashtags.php?parameter_1=$1&parameter_2=$2 [QSA,L]
当我添加 B 标签后,它就正常工作了:
RewriteEngine On
# convert path strings into query strings
RewriteRule "^(.*)/(.*)/hashtags.php" /hashtags.php?parameter_1=$1&parameter_2=$2 [QSA,L,B]
使用 %23 对 URL 中的哈希进行编码
http://twitter.com/home?status=I+believe+in+%23love
“我相信爱情”
URL编码参考:http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)