Okay - the logic of my brain is far from the logic of how code in a .htaccess file gets processed... to bad as it get frustrating sometimes when you try to achieve something "logical".
I would like to set a custom ErrorDocument when variable MAINTENANCE_MODE is set but it will simply not load the correct file. Is this because the If-directive is looked at earlier than the RewriteRules?
SetEnv MAINTENANCE_MODE 1
ErrorDocument 503 /msg/503_default.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:MAINTENANCE_MODE} 1
RewriteRule ^ - [E=MAINTENANCE_503:1]
</IfModule>
<If "%{ENV:MAINTENANCE_503} == '1'">
ErrorDocument 503 /msg/503_maintenance.php
RewriteRule !^503 - [R=503]
</If>
When it's totally not possible, which alternative route would be producing the best result?
Would that be to create a 503_default.php which can receive a value so it knows which custom message to show? If so, how do I set/pass that value onto the default 503 page?
Btw - this is just a simplified base version of what it will have to become. I also have other scenario's in which I want to serve a custom 503 message. But without a base there is not point in writing extended code :)
Okay - with help of the input from MrWhite to this and my previous question I managed to land on a working solution with a custom ErrorDocument 503. Thanks @MrWhite!
The requirement
A custom 503 message for 3 specific situations:
The solution
The .htaccess file
Let's start with the .htaccess file. The (simplified) code I landed on is:
With
GEO_BLOCK_MODEset to1the section is enabled.Then we check if the page is not a redirected page with code 503 before we continue with the other conditions we want to be applicable to the situation.
At the end we redirect to 503 and set a
503_MODE$_SERVER variable we can retrieve in our 503_handler.php viaREDIRECT_503_MODE.The other 2 sections are setup in the same fashion and with regards to the
PRODUCT_RELEASE_MODEsection... there are 2 cronjobs running on the server:The 503_handler.php file
The code in our .htaccess leads us to a custom 503 handler file. Which I have setup as follow to suit my needs:
Okay - this is just the bare bones of my custom 503_handler.php file but it gives you a clear idea on how to set it up and how to capture the values we've setup / generated within our .htaccess code.
That's it
And that is it.
I now have a working solution to show custom 503 messages for the 3 defined satiations and best of all:
Sweet!