开发者

Problem with multiple rewrite rules

开发者 https://www.devze.com 2023-01-14 04:08 出处:网络
I have this rule which redirects all requests without a . in them to index.php, and it works fine: # Redirect all page requests to content handler

I have this rule which redirects all requests without a . in them to index.php, and it works fine:

# Redirect all page requests to content handler
RewriteRule ^([^.]*)$ index.php [L]

Now I'd also like to disallow any requests where the original URL contains .php in it. When I add another rule like this (after the first one), the first rule breaks:

# Disallow access to PHP files
RewriteRule \.php 404.php [L]

I thought that adding [L] to the first rule would stop 开发者_如何学Pythonthe second rule from being executed, but it seems to have no effect: the output from the first rule (i.e. index.php) matches the second rule and all requests end up in 404.php. What am I doing wrong here?


The [L] means no more rules are processed for this request, but the entire path is triggered again when index.php is being processed. Try adding a new rule making the 404 rule fire only if the requested page isn't index.php, something like this:

# Disallow access to PHP files
RewriteCond %{REQUEST_FILENAME} !=index.php
RewriteRule \.php 404.php [L]
0

精彩评论

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