【问题标题】:# tag Not rewrite in htaccess file# 标签不会在 htaccess 文件中重写
【发布时间】:2015-05-13 10:45:22
【问题描述】:

我在 .htaccess 文件中遇到了#标签的问题。 问题是

       http://localhost/query/index.php?string=abc%23123

这里我们通过urlencode() 方法对查询字符串进行编码。

实际值为

abc#123

但它在$_REQUEST[] 方法上产生了问题..

所以有人建议我使用urlencode()

我通过接受建议来使用它。但现在它在 url重写。

.ht访问码是

RewriteRule ^([A-Za-z0-9-]+).html?$ index.php?string=$1 [NC,L]

现在当我点击查询字符串页面时

它显示404 未找到 http://localhost/query/abc%23123.html

所以请帮助我在浏览器上显示该页面,例如

http://localhost/query/abc#123.html

所以请建议我将在我的 .htaccess 文件中更改哪些内容,以下 url 将适用于我

【问题讨论】:

  • 使用 NE 标志 .... [NC,NE,L]
  • Starkeen 你能推荐我吗

标签: php regex .htaccess url url-rewriting


【解决方案1】:

您可以将此规则与B 标志一起使用:

RewriteRule ^([^.]+)\.html?$ index.php?string=$1 [NC,L,QSA,B]

这会将未编码的http://localhost/query/abc%23123.html 传递给index.php。在index.php 内部,当您使用$_GET['string'] 时,它将打印:

query/abc#123

【讨论】:

  • 感谢现在 404 问题已解决,但 url 保存为以前的 localhost/query/abc%23123.html 我希望它是 localhost/query/abc#123.html
  • 不,那是做不到的。如果像 localhost/query/abc#123.html 这样输入 URL,那么 Web 服务器只会将其视为 localhost/query/abc。浏览器在# 之后留下部分,然后将其发送到服务器。
猜你喜欢
  • 2020-07-14
  • 2016-09-16
  • 2012-05-19
  • 1970-01-01
  • 2017-08-10
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多