Php mod_重写无法正常工作-访问静态资源
现在我的网站根目录中有几个文件夹(img、css、js和ico)。但是,我想将它们移动到一个名为public_html的新目录中。例如,图像文件夹不是位于/img中,而是位于/public\u html/img中。但我在执行此操作时遇到问题,我怀疑这是我的.htaccess文件的问题Php mod_重写无法正常工作-访问静态资源,php,mod-rewrite,Php,Mod Rewrite,现在我的网站根目录中有几个文件夹(img、css、js和ico)。但是,我想将它们移动到一个名为public_html的新目录中。例如,图像文件夹不是位于/img中,而是位于/public\u html/img中。但我在执行此操作时遇到问题,我怀疑这是我的.htaccess文件的问题 Options -Indexes Options +FollowSymLinks RewriteEngine On ErrorDocument 404 static/404.html ErrorDocument
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
ErrorDocument 404 static/404.html
ErrorDocument 403 static/403.html
RewriteCond %{REQUEST_FILENAME} !-f
# ---------- Custom Routes ----------------
# -----------------------------------------
RewriteRule ^(js|css|img|ico)\/(.+)$ public_html/$1/$2
RewriteRule ^(.*)$ index.php?r=$1 [L,QSA]
我可以很好地访问/public_html/css/style.css,但是当我添加第一行重写规则并尝试访问/css/style.css时,它不起作用
有人知道为什么吗?谢谢 将
[L]
标志添加到第一条规则。否则,它将跳转到第二条规则,并尝试在r=
中将其传递到index.php
。通过public\u html
访问它是有效的,因为RewriteCond%{REQUEST\u FILENAME}-f
RewriteRule ^(js|css|img|ico)\/(.+)$ public_html/$1/$2 [L]
# Update: Try using the RewriteCond before this line
# as well as where you have it earlier
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?r=$1 [L,QSA]
似乎[L]标志不起作用,因为当我注释掉第二行时,它工作得很好。@RLC尝试在我刚才编辑的最后一行之前再次添加
RewriteCond
。