【问题标题】:hashtag in apache .htaccessApache .htaccess 中的标签
【发布时间】:2014-06-25 09:43:50
【问题描述】:

通过使用以下 .htaccess

RewriteEngine On
RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L]

当用户在浏览器中键入以下 URL 时。

http://localhost:8080/1/2

我期待,Apache 将执行内部重定向,并在浏览器上更改显示的 URL(通过 R=301)。

http://localhost:8080/api/web/index.html#1/2

在浏览器中更改显示的 URL 很重要。这是为了保证index.html的JavaScript能够正确解析url。

然而,我真正得到的是

http://localhost:8082/api/web/index.html%231/2

我会得到 Apache 错误。

Apache 错误地认为,我希望获取位于目录 api/web/index.html%231/ 中的名为 2 的文件

有什么我可以通过修改.htaccess来解决这个问题的吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    # 被编码为%23。尝试在规则中使用 NE 标志:

    RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L,NE]
    

    NE 标志告诉 mod_rewrite 不要对 URI 进行编码。

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 2015-04-05
      • 2012-03-09
      • 2016-09-16
      • 1970-01-01
      • 2021-04-17
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多