my htaccess file is that:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*
RewriteCond %{QUERY_STRING} .* [NC]
RewriteRule .*\.php cms/index.php?request=$0&%{QU开发者_开发问答ERY_STRING} [L]
RewriteRule ^(?:(?!website).).*\.(?:(?!php).)+$ cms/website/$0 [L]
RewriteRule ^[^./]*(\/[^./]*)*$ cms/index.php?dirs=$0 [L]
for example there is a file in uploads/aa.png, and if I request http://example.com/uploads/aa.png, it still redirect http://example.com/website/uploads/aa.png.
shortly, if there is file at the url requested it still redirect "cms/website", how can I disable that?
The RewriteCond directive only applies to the next RewriteRule. (Only one.)
So your rewrite conditions apply only to your first RewriteRule. The other rewrite rules are unconditional.
You have to repeat the RewriteCond's for each RewriteRule, or set an environment variable:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? - [E=FILE_EXISTS:1]
RewriteCond %{ENV:FILE_EXISTS] !=1
RewriteRule .*\.php cms/index.php?request=$0&%{QUERY_STRING} [L]
RewriteCond %{ENV:FILE_EXISTS] !=1
RewriteRule ^(?:(?!website).).*\.(?:(?!php).)+$ cms/website/$0 [L]
RewriteCond %{ENV:FILE_EXISTS] !=1
RewriteRule ^[^./]*(\/[^./]*)*$ cms/index.php?dirs=$0 [L]
1. What is the point in having these lines?
RewriteCond %{REQUEST_URI} .*
RewriteCond %{QUERY_STRING} .* [NC]
They do nothing except wasting CPU cycles.
2. You already have good answer from @arnaud576875. Here is another approach which may work better (or may not fit your needs) -- it really depends on your overall rewrite logic:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# do not do anything for already existing files
# (no need to check for this condition again for other rules)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# your rewrite rules -- they work with non-existed files and folders only
RewriteRule .*\.php cms/index.php?request=$0 [QSA,L]
RewriteRule ^(?:(?!website).).*\.(?:(?!php).)+$ cms/website/$0 [L]
RewriteRule ^[^./]*(\/[^./]*)*$ cms/index.php?dirs=$0 [L]
NOTES:
I've got rid of
&%{QUERY_STRING}
in first rewrite rule --QSA
flag does the same, even better.Your matching pattern in first rewrite rule:
.*\.php
-- this is ain't great as will match/hello.php.png/tell-me-something
as well. If that is OK -- no probs then, but if you wanted to only match requests to .php files (e.g./interesting/text.php
), then it will be better to add$
at the end: it to.*\.php$
精彩评论