How to setup 503 maintenance page while allowing certain IPs?

How do we setup a maintenance page – that blocks out everyone except for my IP address? I have this in place and it does not work – as the server isn’t seeing my IP but an IP from Cloudflare. If I give that IP address access I am open the door to everyone once again.

RewriteCond %{REMOTE_ADDR} !^00\.00\.00\.0
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"

Googled it and found the solution on Stackoverflow. In case someone else requires it.

RewriteCond %{HTTP:X-FORWARDED-FOR} !^00.00.00.0

1 Like