Use RewriteCond based on environment variable in .htaccess

后端 未结 3 1461
北荒
北荒 2021-02-02 17:59

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 rew

3条回答
  •  渐次进展
    2021-02-02 18:51

    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]
    

    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."

提交回复
热议问题