Apache maintenance redirect

I created a script to have apache redirect viewers to a maintenance page, but still allow me to view the site normally using an IP address exception. The problem is, after doing a quick test, the script doesn't redirect to the maintenance page at all. It worked on the previous servers I've used it on.

 <ifmodule mod_rewrite.c="">RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^255\.255\.255\.255$ #IPv4
RewriteCond %{REMOTE_ADDR} 0000:0000:0000:0000:0000:0000:0000:0000 #IPv6
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|svg|css|js) [NC]
RewriteRule .* /maintenance.html [R=302,L]</ifmodule> 

3 Replies

Update: After taking some time to learn more about managing a server, I recently went back to dredge up my script. After making some simple fixes to get it working correctly. I now have an Apache redirect that will redirect all visitors to a maintenance page

You welcome to use this script and make any edits for your own needs.

https://github.com/jcgallaher/website-maintenance-mode

Edit: Upon doing more testing. The redirect is working, but the IP address exception only seems to work on the machine I'm making the changes with, but other computers on the network with the same external address get the maintenance page. For example, my wife's computer, my iphone, and my daughter's iPhone show the maintenance page. I've cleared the cache and retested it on every device to ensure that the browser cache isn't affecting the results, but that doesn't seem to have any influence. I can confirm this since on my machine, I changed the IP address just one number, saved it, restarted apache, refresh the page, and the maintenance page shows up again. Change it back, to the correct IP, save it, restart apache, refresh the page, and I see the site as normal.

I discovered what the issue was. It was to do with IPv6. If you are behind a router, one who has conventional knowledge of them would assume that the external address that you get would be network wide. However, that's not the case, if you do a google search for your ip address and you get the long IPv6 address, that address will work for your machine only. If additional people are working on the site, they need to check their IP too and it needs to be added into RewriteCond %{REMOTE_ADDR} too.

I confirmed this by checking my router's System Log - IPv6 Network Information. Each computer on the network had a different IPv6 address. I also tested it by changing the IP address for that other machine and it showed the normal site.

Hopefully if you're using my script or something similar and you're running into this issue, this will save you many hours of trouble shooting. I'll be looking into a solution for using multiple IP's and update the documentation.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct