I have the following ht开发者_开发知识库access script:
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(test|test1).* - [L]
I was expecting that: http://localhost/something.php will redirect to index.php
True.
I was expecting that http://localhost/test.php will NOT redirect to index.php
False. (I'm getting redirected as well).
What am I missing?
Thanks a lot
Rewrite Rules are always evaluated in the order they are specified. So both your URLs will match the RewriteRule in line 3. The other rules will not get evaluated. To have your test files not rewritten, you could put the last three rules more to the top (i.e. directly below the RewriteBase command).
But in the end, you should probably use RewriteConds more, e.g. like this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^(test|test1)
# the following RewriteCond is probably redundant because of the prior -f check
RewriteCond %{REQUEST_FILENAME} !\.(js|ico|txt|gif|jpg|png|css)$
RewriteRule (.*) index.php
精彩评论