【发布时间】:2017-08-25 15:37:40
【问题描述】:
我在使用 htaccess 执行规则时遇到问题,如果规则匹配,则不要检查其他规则。我试图从过去几个小时中弄清楚。下面是示例代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/projectname/$
#RewriteCond %{REQUEST_URI} !projectname/(storage)$
RewriteRule ^(.*)$ /projectname/abc/dist/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} projectname/(storage)$
RewriteRule ^(.*)$ /projectname/storage/$1 [L]
Rewritecond %{REQUEST_URI} projectname/(.*)$
#RewriteCond %{REQUEST_URI} !projectname/(storage)$ [NC]
RewriteCond %{REQUEST_URI} !\.(html?|png|woff|ttf|eot|svg|woff2|jpg|gif|xml|rss|png|css|js|json)$ [NC]
RewriteRule ^(.*)$ /projectname/#/$1 [NE,R=301,L]
RewriteRule ^(.*)$ /projectname/abc/dist/$1 [L]
我想从 projectname/abc/dist 文件夹中加载所有内容,但不适用于当我在 url 中有存储时,我只想从存储文件夹中加载数据。 因此,根据此处定义的规则,一切正常,但是当我在 url/src 中存储图像时,它仍然检查 /projectname/abc/dist/storage/xxxx.png 而不是检查 htaccess 中定义的 /projectname/storage/xxxx.png规则。
我已尝试使用 [S=5] 跳过与 htaccess 中的存储规则不工作从参考 http://httpd.apache.org/docs/2.4/rewrite/flags.html。
根据我的理解 [L] 是最后一个,所以它应该在存储规则之后停止 htaccess 但它没有。
我尝试在 htaccess 中实现 IF ELSE,但我为 IF ELSE 尝试的示例甚至没有帮助。 参考https://blogs.apache.org/httpd/entry/new_in_httpd_2_4 参考http://httpd.apache.org/docs/2.4/rewrite/flags.html(检查跳过 IF ELSE 节)
任何想法都会有用。
【问题讨论】:
-
尝试在网页的 head 部分添加
-
已经添加解决了重新加载问题。 @starkeen。没有可能是错过添加/projectname/。让我试试。
-
我的回答对你有用吗?希望得到简短的反馈:)
-
不,它不起作用@Hello Fishy .. 它阻止了 Angular 的加载。我现在已经通过将 Angular 放在与 laravel 不同的目录中进行整理。但是,是的,我将寻找解决我提到的问题的方法。一旦我得到它,我会在这里留下一个解决方案。
标签: apache .htaccess mod-rewrite