2014-05-08 14 views
2

通過使用以下的.htaccess#標籤Apache中的.htaccess

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

當用戶鍵入他們的瀏覽器下面的網址。

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

回答

6

#被編碼爲%23。嘗試使用NE標誌在您的規則:

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

NE標誌告訴mod_rewrite的未編碼的URI。