HT Access - Mod Rewrite
If i use:
RewriteEngine On
RewriteRule ^.* controller.php
It would send all requests to controller.php But if controller.php included a css file (/assets/css/main.css) then it wouldn't work, as when the browser called it, it would just redirect to controller.php
Is there a way i ca开发者_运维问答n fix this?
You could add a condition to exclude URLs that can be mapped to actually existing files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.* controller.php
The -f
keyword will test if the absolute path in %{REQUEST_FILENAME}
is a path to an existing regular file in the filesystem and !-f
is just the inverse.
But if you have a fixed list of directories you want to exclude, you could also do this:
RewriteCond $0 !^(assets|foo|bar)/
RewriteRule ^.* controller.php
This condition tests if the match of the whole RewriteRule
pattern (referenced with $0
) does not begin with neither assets/
nor foo/
nor bar/
. If you don’t want to process the match you could also use a negated expression directly in your RewriteRule
directive:
RewriteRule !^(assets|foo|bar)/ controller.php
Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.css$
RewriteRule ^.* controller.php
untested but should work.
精彩评论