Skip to content

Instantly share code, notes, and snippets.

@pitch-gist
Created June 26, 2012 22:21
Show Gist options
  • Save pitch-gist/2999707 to your computer and use it in GitHub Desktop.
Save pitch-gist/2999707 to your computer and use it in GitHub Desktop.
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
<article>
<h1>We&rsquo;ll be back soon!</h1>
<div>
<p>Sorry for the inconvenience but we&rsquo;re performing some maintenance at the moment. If you need to you can always <a href="mailto:#">contact us</a>, otherwise we&rsquo;ll be back online shortly!</p>
<p>&mdash; The Team</p>
</div>
</article>
@Kifle-Tesfay
Copy link

Kifle-Tesfay commented Apr 15, 2025

Thank you all of you.

Let me contribute my 2 cents
Add this in to .htaccess
So only the owner or allowed IP address can access the website when it is under maintenance mode
Read the comment for each section

<IfModule mod_rewrite.c>
  RewriteEngine On

  # -------------------------------------------------------------
  # MAINTENANCE MODE SWITCH
  # Set to "on" to enable maintenance mode, "off" to disable it.
  # This can also be set from Apache config or a PHP script using `SetEnv`.
  # -------------------------------------------------------------
  SetEnvIf Request_URI "^" MAINTENANCE_MODE=on

  # -------------------------------------------------------------
  # 1. ALLOWED IPs: If maintenance mode is ON and user is allowed,
  # redirect them away from /maintenance to the homepage
  # (They shouldn't see the maintenance page)
  # -------------------------------------------------------------
  RewriteCond %{ENV:MAINTENANCE_MODE} =on
  RewriteCond %{REQUEST_URI} ^/maintenance/?$ [NC]
  RewriteCond %{REMOTE_ADDR} ^17\.53\.18\.152$ [OR]
  RewriteCond %{REMOTE_ADDR} ^98\.76\.54\.32$ [OR]
  RewriteCond %{REMOTE_ADDR} ^55\.66\.77\.88$
  RewriteRule ^ / [R=302,L]

  # -------------------------------------------------------------
  # 2. BLOCKED IPs: If maintenance mode is ON and the IP is NOT allowed,
  # redirect everything (except assets and maintenance page) to /maintenance
  # -------------------------------------------------------------
  RewriteCond %{ENV:MAINTENANCE_MODE} =on
  # Allow static assets to be accessed
  RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|png|gif|svg|woff|woff2|ttf|ico)$ [NC]
  # Allow the /maintenance page itself
  RewriteCond %{REQUEST_URI} !^/maintenance(?:\.php)?/?$ [NC]
  # Prevent redirect loop if original request was /maintenance.php
  RewriteCond %{THE_REQUEST} !/maintenance(?:\.php)? [NC]
  # Block if IP is NOT allowed
  RewriteCond %{REMOTE_ADDR} !^17\.53\.18\.152$
  RewriteCond %{REMOTE_ADDR} !^98\.76\.54\.32$
  RewriteCond %{REMOTE_ADDR} !^55\.66\.77\.88$
  RewriteRule ^(.*)$ /maintenance [R=302,L]

  # -------------------------------------------------------------
  # 3. MAINTENANCE MODE OFF: If the mode is off and someone tries to
  # access /maintenance, redirect them to the homepage
  # (No one should see the maintenance page)
  # -------------------------------------------------------------
  RewriteCond %{ENV:MAINTENANCE_MODE} =off
  RewriteCond %{REQUEST_URI} ^/maintenance(?:\.php)?/?$ [NC]
  RewriteRule ^ / [R=302,L]

  # -------------------------------------------------------------
  # 4. BLOCK direct access to /maintenance.php
  # This prevents even allowed IPs from visiting /maintenance.php directly
  # -------------------------------------------------------------
  RewriteCond %{THE_REQUEST} \s/maintenance\.php [NC]
  RewriteRule ^maintenance\.php$ / [R=302,L]

  # -------------------------------------------------------------
  # 5. REMOVE .php EXTENSION
  # Allows users to access /filename instead of /filename.php
  # (e.g., /maintenance will internally map to /maintenance.php)
  # -------------------------------------------------------------
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^([^/]+)/?$ $1.php [L]
</IfModule>

Instead of adding a whole Cloudflare CSS CDN for 3 icons only, you can use these svg icons instead for faster load

<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 1000 1000"><path fill="<?php echo $font_color;?>" d="M182.594 0C81.445 0 0 81.445 0 182.594v634.813c0 101.149 81.445 182.594 182.594 182.594h344.063V609.063H423.282v-140.75h103.375v-120.25c0-94.475 61.079-181.219 201.781-181.219c56.968 0 99.094 5.469 99.094 5.469l-3.313 131.438s-42.963-.406-89.844-.406c-50.739 0-58.875 23.378-58.875 62.188v102.781h152.75l-6.656 140.75H675.5v390.938h141.906c101.149 0 182.594-81.445 182.594-182.594V182.595C1000 81.446 918.555.001 817.406.001H182.593z" /></svg>
 
 <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 1000 1000"> <path fill="<?php echo $font_color;?>" d="M196.064.25C88.347.25.187 88.408.187 196.127v607.841c0 107.717 88.158 195.845 195.877 195.845h607.841c107.718 0 195.845-88.127 195.845-195.845V196.127C999.75 88.41 911.623.25 803.905.25zm49.266 164.948c51.648 0 83.461 33.906 84.443 78.475c0 43.585-32.797 78.444-85.442 78.444h-.969c-50.665 0-83.412-34.857-83.412-78.444c0-44.568 33.738-78.475 85.379-78.475zm445.08 208.31c99.329 0 173.79 64.922 173.79 204.436v260.449H713.247V595.406c0-61.06-21.847-102.718-76.476-102.718c-41.704 0-66.562 28.078-77.476 55.202c-3.987 9.704-4.967 23.257-4.967 36.832v253.671H403.375s1.981-411.613 0-454.233h150.984v64.324c20.06-30.95 55.942-74.977 136.051-74.977zm-521.556 10.685h150.953v454.202H168.854z" /> </svg>

<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"> <path fill="<?php echo $font_color;?>" d="M23.328 19.177c-.401-.203-2.354-1.156-2.719-1.292c-.365-.13-.63-.198-.896.203c-.26.391-1.026 1.286-1.26 1.547s-.464.281-.859.104c-.401-.203-1.682-.62-3.203-1.984c-1.188-1.057-1.979-2.359-2.214-2.76c-.234-.396-.026-.62.172-.818c.182-.182.401-.458.604-.698c.193-.24.255-.401.396-.661c.13-.281.063-.5-.036-.698s-.896-2.161-1.229-2.943c-.318-.776-.651-.677-.896-.677c-.229-.021-.495-.021-.76-.021s-.698.099-1.063.479c-.365.401-1.396 1.359-1.396 3.297c0 1.943 1.427 3.823 1.625 4.104c.203.26 2.807 4.26 6.802 5.979c.953.401 1.693.641 2.271.839c.953.302 1.823.26 2.51.161c.76-.125 2.354-.964 2.688-1.901c.339-.943.339-1.724.24-1.901c-.099-.182-.359-.281-.76-.458zM16.083 29h-.021c-2.365 0-4.703-.641-6.745-1.839l-.479-.286l-5 1.302l1.344-4.865l-.323-.5a13.17 13.17 0 0 1-2.021-7.01c0-7.26 5.943-13.182 13.255-13.182c3.542 0 6.865 1.38 9.365 3.88a13.06 13.06 0 0 1 3.88 9.323C29.328 23.078 23.39 29 16.088 29zM27.359 4.599C24.317 1.661 20.317 0 16.062 0C7.286 0 .14 7.115.135 15.859c0 2.792.729 5.516 2.125 7.927L0 32l8.448-2.203a16.1 16.1 0 0 0 7.615 1.932h.005c8.781 0 15.927-7.115 15.932-15.865c0-4.234-1.651-8.219-4.661-11.214z" /> </svg>

Credit to chatGPT for helping me in the .htaccess code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment