开发者

htaccess script - do NOT allow rewrite for a specific file

开发者 https://www.devze.com 2023-02-11 06:29 出处:网络
I have the following ht开发者_开发知识库access script: RewriteEngine on RewriteBase / RewriteRule !\\.(js|ico|txt|gif|jpg|png|css)$ index.php

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
0

精彩评论

暂无评论...
验证码 换一张
取 消