我是AngularJS和PHP的新手。在我正在开发的应用程序中,我在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);
当我访问我的应用程序使用以下url: http://localhost/myapp,它不会在浏览器url中添加任何#。我可以成功地导航到任何其他路线。路由url为http://localhost/myapp/category/1
但是当我刷新页面时,上面的url给我404错误。我明白了,服务器试图在位置/myapp/类别/1找到文件。我在其他地方读到写。htaccess规则会解决这个问题。我尝试了所有的选择。对我来说什么都不管用。
我使用xampp和。htaccess文件的位置是/htdocs/myapp/.htaccess.htaccess文件是可访问的,因为如果我在其中添加任何垃圾数据,url抛出错误。
请帮我一下。我需要服务器返回url,因为它是这样的angularjs可以正确路由页面。请帮我写。htaccess规则。Mod_rewrite已经在apache的httpd.conf文件中启用了
我可以找到解决方案。我的。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>