Search code examples
wordpress.htaccessmaintenance-mode

Wordpress maintenance mode .htaccess


I have tried multiple ways to host a maintenance page while I update a WordPress blog but to no avail. I get an Internal Server Error.

RewriteEngine On

# Add all the IP addresses of people that are helping in development
# and need to be able to get past the maintenance mode.
# One might call this the 'allow people list'
RewriteCond %{REMOTE_HOST} !^83\.101\.79\.62
RewriteCond %{REMOTE_HOST} !^91\.181\.207\.191

# Make sure the <em>maintenance mode</em> only applies to this domain
# Example: I am hosting different sites on my server
# which could be affected by these rules.
RewriteCond %{HTTP_HOST} ^nocreativity.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.nocreativity.com$

# This is the 'ignore file list'. It allows access to all
# files that are needed to display the <em>maintenance mode</em> page.
# Example: pages, css files, js files, images, anything.
# IMPORTANT: If you don't do this properly, visitors will end up with
# endless redirect loops in their browser.
RewriteCond %{REQUEST_URI} !/offline\.htm$
RewriteCond %{REQUEST_URI} !/css\/style\.css$
RewriteCond %{REQUEST_URI} !/images\/logo\.png$

# Rewrite whatever request is coming in to the <em>maintenance mode</em> page
# The R=302 tells browsers (and search engines) that this
# redirect is only temporarily.
# L stops any other rules below this from executing whenever somebody is redirected.
RewriteRule \.*$ /offline.htm [R=302,L]

The code above is from No Creativity

I've also tried...

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

... from WP Beginner

Is there any issue with just changing the name of index.php in the top directory to _index.php and renaming my maintenance.html file to index.php?


Solution

  • RewriteEngine On
    
    # Add all the IP addresses of people that are helping in development
    # and need to be able to get past the maintenance mode.
    # One might call this the 'allow people list'
    RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444
    
    # Make sure the <em>maintenance mode</em> only applies to this domain
    # Example: I am hosting different sites on my server
    # which could be affected by these rules.
    RewriteCond %{HTTP_HOST} ^yourdomain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
    
    # This is the 'ignore file list'. It allows access to all
    # files that are needed to display the <em>maintenance mode</em> page.
    # Example: pages, css files, js files, images, anything.
    # IMPORTANT: If you don't do this properly, visitors will end up with
    # endless redirect loops in their browser.
    RewriteCond %{REQUEST_URI} !/maintenance\.html$
    RewriteCond %{REQUEST_URI} !/somejavascriptfile\.js$
    RewriteCond %{REQUEST_URI} !/css\/yourstylesheet\.css$
    RewriteCond %{REQUEST_URI} !/img\/yourlogo\.jpg$
    
    # Rewrite whatever request is coming in to the <em>maintenance mode</em> page
    # The R=302 tells browsers (and search engines) that this
    # redirect is only temporarily.
    # L stops any other rules below this from executing whenever somebody is redirected.
    RewriteRule \.*$ /maintenance.html [R=302,L]
    

    This is a sample from what I used, originally from No Creativity but for some reason didn't work.