我试图在 .htaccess 文件中定义一个环境变量,然后使用该变量运行重写条件。以下是我的 .htaccess 文件中的内容,但重写不起作用:
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 收到来自 GitHub 挂钩之一的发布请求以拉取存储库进行更新时,让 PHP 编辑 .htaccess 文件,从而以编程方式将站点设置为维护模式。
mod_rewrite 不使用通过 SetEnv 设置的变量,而是使用此方法:
#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 个内部重定向的限制”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)