2016-09-19 46 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>