Apache mod_rewrite REDIRECT_STATUS 条件导致目录列表 [英] Apache mod_rewrite REDIRECT_STATUS condition causing directory listing

查看:17
本文介绍了Apache mod_rewrite REDIRECT_STATUS 条件导致目录列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 htaccess 重写规则.防止循环的单规则条件最初是这样写的:

I have the following htaccess rewrite rules. The one rule condition to prevent looping was originally written this way:

RewriteCond %{ENV:REDIRECT_STATUS} ^.

它曾经工作得很好,直到它突然停止工作,导致 Apache 显示网站的目录列表.

It used to work just fine, until it suddenly stopped working causing Apache to display the directory listing of the website.

我不得不将其更改为这种新形式,如下面的清单所示,以使其再次工作:

I had to change it to this new form, as in the listing below, to have it work again:

RewriteCond %{ENV:REDIRECT_STATUS} 200

你知道这种行为的原因吗?

Do you have any idea of the reason of this behaviour?

谢谢

RewriteEngine on
RewriteBase /

## Permanent 301

## Force to www. Un-comment in production.
RewriteCond %{HTTP_HOST} !^www\.myhost\.com [NC]
RewriteRule ^(.*) http://www.myhost.com/$1 [L,R=301]

## Permanent redirect rules for contents

RewriteRule ^argument/programming/?$ tags/programming [NC,L,R=301]

## Internal Redirect Loop Protection
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

## Maintenance page
#RewriteRule (.*) special/maintenance.html

## Specials
RewriteRule special/(.*) special/$1 [NC,L]

## Static resources
RewriteRule ^(.*\.(js|ico|gif|jpg|png|css|rss|xml|htm|html|pdf|zip|gz|txt))$ public/$1 [NC,L]

## Front Controller
RewriteRule ^(.*) public/index.php [NC,L]

推荐答案

你有这个条件来停止循环:

You have this condition to stop looping:

## Internal Redirect Loop Protection
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

这通过检查 Apache 内部变量 %{ENV:REDIRECT_STATUS} 起作用.此变量在重写模块开始时为空,但在第一次成功的内部重写发生时设置为 200.上述条件表示在第一次成功重写并停止循环后退出进一步的重写.

This works by checking internal Apache variable %{ENV:REDIRECT_STATUS}. This variable is empty at the start of rewrite module but is set to 200 when first successful internal rewrite happens. This above condition says bail out of further rewrites after first successful rewrite and stops looping.

这篇关于Apache mod_rewrite REDIRECT_STATUS 条件导致目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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