htaccess rules to skip files and directory but checking by matching with a prefix first

吃可爱长大的小学妹 提交于 2020-01-26 02:22:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!