我在 .htaccess
中有类似以下内容:
RewriteRule ^a/(.+)$ index.php?data=$1 [L]
足够简单,适用于大多数情况,除非我使用以下 URL:
http://example.com/a/hello%23abc
我希望这会将 data
GET 变量设置为 hello#abc
,但它却中断了。我认为它会中断,因为 Apache 对字符进行了“转义”,使 url 如下:
index.php?data=hello#abc
这可能就是它将 data
GET 变量设置为 hello
的原因。
有什么办法可以解决这个问题吗?
谢谢。
最佳答案
使用 [B] 标志应该对您的情况有所帮助(在 Apache 2.2 中可用)
The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation.
RewriteRule ^a/(.+)$ index.php?data=$1 [L,B]
关于php - 如何转义 .htaccess 中的井号 (#) 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304244/