mod_rewrite .htaccess problem
i have the following lines in my htaccess to rewrite the css files to another location:
RewriteCond {REQUEST_FILENAME} !-f [NC] OR
RewriteCond {REQUEST_FILENAME开发者_StackOverflow中文版} !-d [NC]
RewriteRule ^\\/?(.*)\.(css|js)$ public/$2/$1.$2 [L,NC,NE]
but when the site tries to load the files, there is an errer of a misconfiguration. the actual problem is the dot between $1 and $2. i think when the server finds the file then it gets into an infinite loop.
does anyone know the reason for that error?
It's been a while since I looked at the syntax for some of this, but I thought that the OR
would be within the brackets. That said, that is part of your problem; you need both RewriteCond
conditions to be true. Also, you need the file actually to be present; if the file is not found, you will enter an infinite loop anyway. Another approach might be:
RewriteRule ^public/(css|js)/ - [NC,L]
prior to the RewriteCond
directives so that nothing in public/css
or public/js
gets rewritten, regardless of whether it is there.
Also, in per-directory context (i.e., .htaccess), the value that RewriteRule
matches does not begin with a slash. That's not causing your problem, but it could save you a few characters and make your regex simpler to read.
Write your rule like this to avoid infinite looping:
RewriteRule ^(?!public/)(.*)\.(css|js)$ public/$2/$1.$2 [L,NC]
Negative look ahead will prevent infinite looping for you.
It gets into infinite loop because the directory that you are redirecting also satisfies the regex.
精彩评论