重写规则最后[L]标志不工作? [英] RewriteRule Last [L] flag not working?

查看:161
本文介绍了重写规则最后[L]标志不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

php_flag display_errors 1
php_value auto_prepend_file init.php
RewriteEngine on 
RewriteRule ^$  /id/authenticate [R]
RewriteRule ^login_openid$  /id/login_openid.php [QSA,L]
RewriteRule ^authenticate$  /id/authenticate.php [QSA,L]
RewriteRule ^facebook$  /id/facebook.php [QSA,L]
RewriteRule ^createfromopenid$  /id/createfromopenid.php [QSA,L]

RewriteRule .* - [L,R=403]

这是我的.htaccess文件。在SERVERCONFIG我只是所有的AllowOverride

This is my .htaccess file. In the serverconfig I just have AllowOVerride all.

如果我请求URL http://mydomain.com/id/authenticate 我得到一个403错误。如果我删除了最后一条规则,它的工作原理。不应该在 [L] 平prevent的发生任何进一步的规则?

If I request the URL http://mydomain.com/id/authenticate I get a 403 Error. If I remove the last rule, it works. Shouldnt the [L] flat prevent any further rules from happening?

编辑:

我的htaccess文件是在子文件夹ID,所以规则的工作。

My htaccess file is in the subfolder "id", so the rules work.

推荐答案

[L] 规则正常工作 - 你只是不知道是怎么回事的实际工作

The [L] rule works fine -- you just do not know how it actually works.

当Apache看到 [L] 国旗和规则匹配(重写时),Apache将转至下一次迭代并开始匹配< STRONG>再从顶部全部规则。在 [L] 标志的意思是请不要在此迭代过程下面的任何规则

When Apache sees the [L] flag and rule matches (rewrite occurs), Apache will go to next iteration and will start matching all rules again from top. The [L] flag means "do not process any rules below in this iteration".

是,在 Apache文档 不是100 %明确这个(这意味着它可以改进),但提供了足够的信息来弄明白最后。

Yes, the Apache documentation is not 100% clear on this (which means it can be improved), but provides enough info to figure it out eventually.

Apache会在少数情况下停止重写周期:

Apache will stop rewrite cycle in few situations:


  1. 没有在所有匹配规则(没有发生重写);

  1. No rules matched at all (no rewrite occurred);

立即退出的规则相匹配(例如重写规则* - [L] );

"exit now" rule matched (e.g. RewriteRule .* - [L]);

发生重写,但输入网址和最终网址是相同的2〜3次迭代(发生在翻江倒海的书面规则重写相同的URL相同的URL。

Rewrite occurs, but input URL and final URLs are the same (happens on 2nd-3rd iteration when "badly" written rule rewrites the same URL to the same URL.

例如的RewriteRule(。*)/index.php?page=$1 [L]


  • /你好 => /index.php?page=hello

  • 关于下一次迭代
  • 将重写的index.php => /index.php?page=index.php

  • 和第三个迭代这将是的index.php => /index.php?page=index.php ..现在是没有意义的);

  • /hello => /index.php?page=hello
  • on next iteration it will rewrite /index.php => /index.php?page=index.php
  • and on 3rd iteration it will be /index.php => /index.php?page=index.php .. which makes no sense now);

重写迭代限制到达(默认= 10) - 这就是,如果你进入无限循环重写(该值由<受控href=\"http://httpd.apache.org/docs/current/mod/core.html#limitinternalrecursion\">LimitInternalRecursion指令)。

Rewrite iteration limit is reached (by default = 10) -- that's if you entered infinite rewrite cycle (the value is controlled by LimitInternalRecursion Directive).

使用上述所有信息,我可以说,如预期 您目前的规定做的工作。这意味着,你必须改变的逻辑,摆脱过去的规则(也许处理这个时刻在父母的.htaccess ..或不同的方式处理它 - 一切都取决于你的应用程序的构建方式,我不想做乱撞)。


With all aforementioned information I can say that your current rules do work as expected. This means that you have to change the logic and get rid of the last rule (maybe handle this moment in parent .htaccess .. or handle it differently -- all depends on how your application is built, I do not want to make wild guesses).

这篇关于重写规则最后[L]标志不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆