我使用的htaccess如下
RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} -U
RewriteRule ^.*$ - [NC]
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.*)$ #/$1 [L]
在我的本地主机上,当我只需输入 localhost/时,它会重定向到 localhost/home 并且我的 Angular 应用程序运行完美。但是当我直接输入 url localhost/home 时,它会抛出 404。 我需要将其重写为 localhost/#/home
在我的 Angular 应用程序中,在index.html header 中,我添加了$locationProvider.html5mode(true),html5模式正在工作,但唯一的问题是刷新浏览器时...
提前感谢大家。
最佳答案
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.html [L]
关于angularjs - 如何在 apache htaccess 中为 angularjs 应用程序重写 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147465/