2013-05-31 109 views
0

我已經構建了一個角度站點。一切都很好。如果我去本地主機,它會使主頁很好。我可以點擊一個鏈接,它會帶我到那裏很好,但如果我刷新頁面時,我不在根頁面,或者如果我嘗試輸入一個URL,它給了我一個404。我有$locationProvider.html5Mode設置爲真正。如何解決這個問題?我認爲這將在Apache的httpd.conf中,但我不確定。鏈接到不在根的AngularJS站點

回答

1

使用<base href="/" />標籤

0

這篇文章給出了問題的一個很好的說明:

http://www.josscrowcroft.com/2012/code/htaccess-for-html5-history-pushstate-url-routing/

這表明加給你的.htaccess文件(你也可以直接將它添加到你的Apache CONF)。你必須有mod_rewrite加載到Apache。

# html5 pushstate (history) support: 
<ifModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !index 
    RewriteRule (.*) index.html [L] 
</ifModule>