+64-3-3595735

Home » Website Development And Support » Coding » .HTAccess Redirect to Maintenance Page

.HTAccess Redirect to Maintenance Page

The following .htaccess code will allow you to set a 301 redirect on your site – using a set of ip addresses that can still log in. Ideal for fixing up things if there has been a hack or other issue.


# MAINTENANCE-PAGE REDIRECT

RewriteEngine on
#add IP addresses that are allowed to access the site in the lines below
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
# allow access to the maintenance.htm file
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
# send all other ips to the maintenance file
RewriteRule .* /maintenance.html [R=302,L]