2016-09-19 49 views
0

我是AngularJS和PHP的新手。在我的工作中的應用,我已經啓用html5mode使用下面的事情angularjs: -如何編寫.htaccess重寫規則來解決404錯誤當angularjs html5mode啓用

-- Added base href in /myapp/index.html 
<base href="http://localhost/myapp/" /> 

-- Added following at the end of config function. 
$locationProvider.html5Mode(true); 

當我使用以下網址訪問我的應用程序:http://localhost/myapp, 它不附加在瀏覽器的URL任何#。我可以成功導航到任何其他路線。路線網址是http://localhost/myapp/category/1

但是當我刷新頁面時,上面的url給我404錯誤。我明白了,服務器試圖在位置/ myapp/category/1上找到文件。我在其他地方讀過.htaccess規則將解決這個問題。我嘗試了所有這些選項。沒有爲我工作。

我使用的XAMPP和.htaccess文件的位置是/htdocs/myapp/.htaccess .htaccess文件是可訪問的,因爲如果我把它添加任何垃圾數據,URL拋出錯誤。

請幫我解決這個問題。我需要服務器來返回url,這樣angularjs才能正確地路由頁面。請幫我寫一下.htaccess規則。 mod_rewrite已經在apache的httpd.conf文件中啓用。

回答

0

我可以找到解決方案。我的.htaccess文件如下所示:

Options +FollowSymLinks 

<ifModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !index.html 
    RewriteCond %{REQUEST_URI} !.*\.(map|css¦js|html|png) 
    RewriteRule (.*) index.html [L] 
</ifModule>