简体   繁体   中英

How can I check whether file exists or not in specific folder in .htaccess?

this is my code,

RewriteCond %{DOCUMENT_ROOT}application/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}application/public%{REQUEST_URI} -d 
RewriteRule application/public/.* - [L]

but when I entered to localhost/css/style.css it is 404 page, although application/public/css/style.css exists.

I think you mean:

RewriteEngine On
RewriteBase /

RewriteRule ^application/public/.* - [L]

RewriteCond %{DOCUMENT_ROOT}/application/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/application/public%{REQUEST_URI} -d 
RewriteRule .* /application/public/$0 [L]

The first rewriteRule prevent the following rule from being executed when the url starts with /application/public/ . It also prevent the following rule from being applied more than once, although that is unlikely to happen in this specific case.

The second rule(-set) will internally redirect all request to the /application/public/ folder, if and only if the requested filename/directory exists in that folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM