javascript - 使用 htaccess 重写 URL 得到 404 错误 - AngularJS html5 模式
问题描述
删除 # 和后 Angular js 页面刷新 404 错误!来自网址
我正在处理一个 angular(1.7.5) 项目,我想在其中删除 # 和 ! 从 URL,为此,我使用以下代码
myApp.config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
}]);
并在根文件夹的 index.html 中添加了基本标记
<base href="/myApp/">
和 .htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
最后,我删除了 # 和 ! 来自 URL,但问题是当我刷新页面或在新选项卡中打开相同的 URL 时,页面出现 404 错误,
http://localhost/dev/ ----- works fine
但
http://localhost/dev/login ----404 error
我不知道如何解决问题帮助我谢谢。
解决方案
尝试.htaccess
像这样修改规则:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]
推荐阅读
- javascript - javascript onevent 元素,返回被点击元素的 id
- sql - 如何在 Oracle SQL 的 Where 语句中添加大小写
- java - 转到实现 Intellij 返回 .class 文件
- java - 什么是 HttpRequestBase#releaseConnection 用于 Apache httpclient-4.5.x
- python - 试图在 docker 中堆放我的目录(运行 pyspark)
- c++ - 指向设备对象成员的指针
- java - 在特定异常的情况下无法连续重试骆驼路线
- python - tkcalendar:使用日历来概览温度数据。(树莓派)
- typescript - 在 typescript 包中导出多个函数
- python - 为什么 collectstatic 不复制我的所有目录?