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

标签 angularjs apache .htaccess mod-rewrite url-rewriting

我已经为使用 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/

相关文章:

javascript - 如何使用 Angular.js 中的某些唯一值从数组中删除值

javascript - 当日期选择器和相邻元素之间没有空格时,Angular-Datepicker 不起作用?

apache - 使用 .htaccess 来提供 index.html 或 index.php

.htaccess - htaccess seo 友好无法正常工作

.htaccess - htaccess 显示内部服务器错误

javascript - 一旦我们有了值,我如何创建对象?

javascript - AngularJS:如何访问元素上的 clientWidth (普通 JS 方法)

apache - 如何编辑 .htaccess 文件以拒绝盗链到 .css、.inc 文件?

apache - 在 CentOs 7 上使用 yum 没有可用的包 httpd

php - 如何更改我的网址显示方式?