There is no "503" response in the code presented here unless you are manually setting the HTTP response status in your server-side script. But if this is a .html
file then that seems unlikely.
To correctly serve a "503 Service Unavailable" response you should define the appropriate ErrorDocument
and call this using the R
flag.
For example:
Options +FollowSymlinks
ErrorDocument 404 /HTML/error-pages/404.html
ErrorDocument 503 /HTML/pages/construction.html
RewriteEngine On
# 503 Service Unavailable except for the given IP address
RewriteCond %{REMOTE_ADDR} !^203\.0\.113\.111$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !\.(jpe?g?|png|gif|css|ico|mp4)$ - [NC,R=503,L]
Despite the use of the R
flag, there is no external redirect here. (A redirect only occurs for status codes in the 3xx range.)
The condition that checks against the REDIRECT_STATUS
environment variable does two things:
It ensures that an internal subrequest for the 503 ErrorDocument itself doesn't trigger a 503 - which would result in an endless loop and no custom ErrorDocument is returned in the response.
A direct request for the /HTML/pages/construction.html
document (the 503 ErrorDocument) will itself trigger a 503 response.
Also note that if you are sending a 503 response, you should ideally be sending a Revisit-After
HTTP response header as well to indicate to (search engine) bots when your site will be available.