Using .Htaccess
If you are using the Apache server, you can use.htaccess
to control access of the directories within the server, and send a response code of the server status.To put the website into maintenance mode, you can use the 503 status code, which indicates that the server is temporarily unavailable.
Before we specify anything in .htaccess, however, we need to create a new file in
.html
or .php
format, and add a message in the file, e.g.
Sorry we are down for maintenance, but we’ll be back up shortly.
Style your page. Next, open the .htaccess file in your server, and add the following:- <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=503,L]
- </IfModule>
This will set the server status code to 503, while also redirects visitors to the maintenance page. You can set your IP address with the following line
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
so that you will still be able to access your website.
No comments:
Post a Comment