Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mod_重写无法正常工作-访问静态资源_Php_Mod Rewrite - Fatal编程技术网

Php mod_重写无法正常工作-访问静态资源

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

现在我的网站根目录中有几个文件夹(img、css、js和ico)。但是,我想将它们移动到一个名为public_html的新目录中。例如,图像文件夹不是位于/img中,而是位于/public\u html/img中。但我在执行此操作时遇到问题,我怀疑这是我的.htaccess文件的问题

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