问题描述
我使用下面的路径是否对他们已经提供了跳过文件的规则。
I am using following rules which skips files if paths to them is already provided.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^$ public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.+)$ public/index.php?r=$1 [L,QSA]
不过,这让我,访问文件就像 site.com/public/js/somefile.js
,这是不intented。
But this makes me, to access the files like site.com/public/js/somefile.js
, which is not intented.
我们就可以知道文件的目录里面存在,并且重写URL,以便访问它的`site.com/js/somfile.js
Can we check if file exists inside a directory and rewrite the url so to access it as `site.com/js/somfile.js"
RewriteCond %{REQUEST_FILENAME} -"public/"f
RewriteRule ^ - [L]
Obvioulsy并没有工作。任何想法?
Obvioulsy this didn't work. Any ideas?
推荐答案
右键这个规则之前:
RewriteRule ^$ public/index.php [NC,L]
添加此规则:
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d
RewriteRule ^(.+)$ /public/$1 [L]