强制RewriteRule结束htaccess文件中的处理/循环 [英] Force RewriteRule to end processing/looping in htaccess file
问题描述
昨天我发现服务器对不支持的HTTP方法的响应不正确.如果不支持HTTP方法,则应使用HTTP 405: Method Not Supported
进行响应. Pandurang能够回答该问题.>
我已经阅读了很多有关[L]
循环的信息,并且花了一些时间浏览所有解决方案
由于某种原因,新代码必须位于底部,这没有任何意义,因为我想避免使用Apache进程所有其他规则最终只能做到这一点.
#Unrelated rule
RewriteRule !\.(css|js|zip)$ index.php [L]
#Rule that now works, only at the bottom
RewriteCond %{REQUEST_METHOD} !^(GET|POST)
RewriteRule .* - [R=405,L]
Yesterday I discovered that my server's response to non-supported HTTP methods was incorrect. If an HTTP method is not supported you're supposed to respond with an HTTP 405: Method Not Supported
. Pandurang was able to answer that question.
I've done a lot of reading about how [L]
loops and I had spent time going through all the Apache 2.4 flag documentation.
- I tried using the
[L]
flag and then the[END]
flag. - I tried to combine flags in every possible way (e.g.
[L,R=405]
,[END,R=405]
) on bothRewriteRule
sets. - I tried combinations where flags where absent.
- I rearranged the order of the rules.
- I tried adding
RewriteCond %{REQUEST_METHOD} ^(GET|POST)$
before the unrelated secondRewriteRule
. - I did a lot of reading.
Here are the two set of rules:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !^(GET|POST)$
RewriteRule .* - [R=405]
#Unrelated rule, when present, breaks the above HTTP 405 turning it in to an HTTP 302:
RewriteRule !\.(css|js|zip)$ index.php [L]
To do testing I ran the following command using cURL:
curl -X PUT -d arg=val -d arg2=val2 https://www.example.com/ -i
I know the HTTP 405 code works via cURL because I can see the response code, just not when the other line is present and I have to have both. What do I need to do to force Apache to stop looping/processing once it matches a rule?
For some reason the new code must be at the bottom, which makes no sense as I'd like to avoid having Apache process all of the other rules to only end up doing this.
#Unrelated rule
RewriteRule !\.(css|js|zip)$ index.php [L]
#Rule that now works, only at the bottom
RewriteCond %{REQUEST_METHOD} !^(GET|POST)
RewriteRule .* - [R=405,L]
这篇关于强制RewriteRule结束htaccess文件中的处理/循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!