Created
February 3, 2023 17:16
-
-
Save ianpegg/9657115fe514ff5b89ce4f3c52e9a021 to your computer and use it in GitHub Desktop.
Maintenance mode .htaccess rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Maintenance mode force redirect rules | |
# Note: based on source code from elsewhere, but I've lost the source. | |
# Let me know if you recognise any of this and want attribution! | |
# We don't need to tell everyone we're apache: | |
ServerSignature Off | |
# Set server admin email | |
ServerSignature EMail | |
SetEnv SERVER_ADMIN you@example.com | |
# ---------------------------------------------------------------------- | |
# Apache: Turn on rewrite engine if available | |
# ---------------------------------------------------------------------- | |
RewriteEngine On | |
RewriteBase / | |
Options All -Indexes | |
Options +FollowSymLinks | |
# ---------------------------------------------------------------------- | |
# Maintenance Mode: remove when ready to set site live! | |
# ---------------------------------------------------------------------- | |
<IfModule mod_rewrite.c> | |
### Either: | |
# 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} !^127\.0\.0\.1 | |
### Or: | |
# Use a custom UA string to circumvent maintenance mode: | |
RewriteCond %{HTTP_USER_AGENT} !^your-custom-user-agent$ | |
# Hint: use Chrome User Agent Switcher to create a custom UA: | |
# @link https://chrome.google.com/webstore/detail/user-agent-switcher/kchfmpdcejfkipopnolndinkeoipnoia | |
# Make sure maintenance mode only applies to this domain | |
# Example: I am hosting different sites or subdomains on the same | |
# server which could be affected by these rules: | |
# RewriteCond %{HTTP_HOST} ^example.com$ [OR] | |
# RewriteCond %{HTTP_HOST} ^www.example.com$ | |
# This is the 'ignore file list'. It allows access to all | |
# files that are needed to display the maintenance mode 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} !/app/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 maintenance mode 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 \.*$ /app/maintenance\.html [R=302,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment