gpt4 book ai didi

angularjs - 如果 url 不包含特定路径,则应用重写规则

转载 作者:行者123 更新时间:2023-12-03 22:25:45 24 4
gpt4 key购买 nike

我已经为使用 html5 路由的 AngularJs 应用程序编写了此重写规则。

重写网址是这样的:

 RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png|html|woff)$
RewriteRule ^ index.html [L]

我想要所有包含路径 的 URL/旧/和路径 /图像/没有重写!

有人可以帮助我,我尝试添加这样的重写条件:
 RewriteCond %{REQUEST_URI} !^/old/

但它不起作用!

问候,
洛伦佐

更新

如果您使用带有路由的 AngularJS,请在 <a> 上使用 target="_self"在同一域中具有链接但不在 Angular 路由下的元素!

最佳答案

您的第三个 RewriteCond没用,因为您已经在第一个条件下检查现有文件。

另外,如果你在一个子目录中(比如 /old/ 或其他东西,你应该在你的 RewriteBase 中添加一个 index.html 或前导斜杠。否则它会在当前目录中查找(可能是 404 错误)。

你可以用这个替换你的代码

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(old|images)/ [NC]
RewriteRule . /index.html [L]

关于angularjs - 如果 url 不包含特定路径,则应用重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com