htaccess rules to skip files and directory but che

2019-09-05 02:33发布

问题:

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]