php - 如何转义 .htaccess 中的井号 (#) 字符?

标签 php apache .htaccess

我在 .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]

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b

关于php - 如何转义 .htaccess 中的井号 (#) 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304244/

相关文章:

php - 当 URL 包含 "index"时,Apache url 重写失败

django - 通过 mod_wsgi 从 apache 传递环境变量以在 django 1.11 设置中使用

.htaccess URL 重写失败 - 在此服务器上找不到请求的 URL

php - 000webhost.com的“自定义错误”页面不起作用?

php - 更改页面标题 - 确定当前页面是什么

PHP检查文件是否包含字符串

ios - Apache BrowserMatch iOS 禁用 keepalive。匹配所有 iOS 版本?

php - 使用 htaccess 删除文件夹名称

php - 将数据库条目转换为大写

php - 使用第二个 jquery 和 php 填充文本字段