2016-06-29 128 views
0

我有一個聚合物站點,我需要編寫一個重寫規則。命名錨的Apache重寫規則

目前有example.com/index.html#contact,example.com/index.html#FAQ等。它的工作原理默認情況下,在瀏覽器中example.com/#contactexample.com/#FAQ,...

我想這是因爲example.com/contactexample.com/FAQ訪問,...

我:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.html#$1 [NE] 

然而,當我將R標誌添加到它「工作」的最後一行。不幸的是,與R標誌的地址變得可見在瀏覽器中作爲example.com/index.html#home,我不希望這一點。

有什麼建議嗎?

回答

0

您不能使用htaccess或mod_rewrite刪除URL片段,因爲它們是從未發送到服務器。就服務器而言,它們不存在。您需要使用JavaScript或其他客戶端解決方案來刪除它們。

Remove fragment in URL with JavaScript w/out causing page reload

+0

謝謝,這很有趣。事實上,我以後可能會需要它。現在,我只是想在服務器上將/ foo內部重定向到index.html#foo。 –