使用的RewriteCond基于在.htaccess环境变量 [英] Use RewriteCond based on environment variable in .htaccess

查看:126
本文介绍了使用的RewriteCond基于在.htaccess环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定我的.htaccess文件中的环境变量,然后使用该变量运行重写条件。下面是我在我的.htaccess文件,但重写不工作:

I am trying to define an environment variable in my .htaccess file, and then run a rewrite condition using that variable. Below is what I have in my .htaccess file, but the rewrite is not working:

RewriteEngine on
#set to 'live' or 'maintenance'
SetEnv ENVIRONMENT maintenance

#If the ENVIRONMENT variable is 'mainetnance' then show a maintenance page to the users
RewriteCond %{ENV:ENVIRONMENT} maintenance
RewriteRule ^(.*)$ /maintenance.html

这样做的目的是通过编程具有PHP编辑.htaccess文件,当它接收到一个请求后从GitHub的钩子一到拉回购的更新设置现场维护模式。

The purpose of this is to set the site to maintenance mode programmatically by having PHP edit the .htaccess file when it receives a post request from one of GitHub's hooks to pull the repo for an update.

推荐答案

mod_rewrite的不使用通过SETENV设置变量,而不是使用此方法:

mod_rewrite doesn't use variables set via SetEnv, instead use this method:

#set to 'live' or 'maintenance'
RewriteRule .* - [E=STATUS:maintenance]

#If the ENVIRONMENT variable is 'maintenance' then show a maintenance page
RewriteCond %{REQUEST_URI} !maintenance.html [NC]
RewriteCond %{ENV:STATUS} ^maintenance$
RewriteRule ^.*$ /maintenance.html [L]

底部的三个的第一行,可以确保一旦用户被重定向到文件maintenance.html时,它不会再重新定向。否则用户不断得到重定向到同一个文件,导致500内部服务器错误说AH00124:请求超过了10内部重定向的限制,由于可能的配置错误

The first line of the bottom three, makes sure that once the user is redirected to the file "maintenance.html", it will not be redirected again. Else the user keeps getting redirected to the same file, causing an 500 internal server error saying "AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error."

这篇关于使用的RewriteCond基于在.htaccess环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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