问题
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]
But this makes me, to access the files like site.com/public/js/somefile.js
, which is not intented.
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 this didn't work. Any ideas?
回答1:
Right before this rule:
RewriteRule ^$ public/index.php [NC,L]
Add this rule:
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d
RewriteRule ^(.+)$ /public/$1 [L]
来源:https://stackoverflow.com/questions/19193098/htaccess-rules-to-skip-files-and-directory-but-checking-by-matching-with-a-prefi