Angular JS编码的URL显示404 page

Angular JS Encoded URL shows 404 Pag

本文关键字:显示 page URL JS 编码 Angular      更新时间:2023-09-26

我已经创建了AngularJS应用程序。

使用下面的URL可以正常工作:

http://localhost/AngularDemo/about

如果我像下面这样修改上面的URL,它会把我带到一个404页面:

http://localhost/AngularDemo%2Fabout

我对。htaccess文件

做了一些修改
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^  index.html#! [L]

这是默认的Apache行为。URL编码斜杠(即。url路径中的%2F)将隐式触发系统生成的 404。这被认为是一个"安全特性"。

如果需要在URL中明确允许编码斜杠,那么您可以在服务器配置中启用此功能:

AllowEncodedSlashes On

参考:
https://httpd.apache.org/docs/2.4/mod/core.html allowencodedslashes

由一些用户代理,如Linked In…

然而,这通常不应该是一个问题。"User-agents"不应该以这种方式编码URL。/AngularDemo%2Fabout可能与/AngularDemo/about是不同的URL

我解决了以下代码。你可以在app.js文件中写

 $locationProvider.hashPrefix('');