【发布时间】:2021-04-10 04:21:57
【问题描述】:
我有一个 Angular 项目,我想将它部署在特定文件夹(不是根目录)上,所以如下所示: http://localhost/folder/index.html 所以我需要在不更改 URL 的情况下重定向此路径上的所有请求。
当 index.html 位于根目录(例如,http://localhost/index.html)时,以下内容可以正常工作:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
所以我尝试像这样更改此代码以用于我的项目:
RewriteRule ^ /folder/index.html
我可以很好地处理这个请求:http://localhost/folder/abcd 但不是 http://localhost/folder/abcd/efgh, http://localhost/folder/abcd/efgh/.../ ..../.....
感谢您的帮助!
【问题讨论】:
-
感谢您分享您的努力,您能否在问题中提及您要重写的从哪个 URL 到哪个 URL?为了更好地理解您的问题。
-
感谢您的回答!实际上,我需要将所有 URL 重定向到此 url 的内容:localhost/folder/index.html 但没有重定向(我不希望浏览器中的 URL 更改)。因此,例如,如果您键入:localhost/folder/blablabla、localhost/folder/blabla/blabla、localhost/folder/blabla/blabla/blabla 等。您必须具有localhost/folder/index.html 的内容。我将使用 javascript 管理请求以适应 html 页面的内容!
标签: angular .htaccess redirect mod-rewrite directory