htaccess rules to skip files and directory but che

2019-09-05 01:51发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-09-05 02:14

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]
查看更多
登录 后发表回答