apache中的#标签.htaccess

时间:2014-05-08 06:28:56

标签: apache .htaccess mod-rewrite redirect

使用以下.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可以正确解析网址。

然而,我真正得到的是

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

我会得到Apache错误。

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

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

1 个答案:

答案 0 :(得分:8)

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

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

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