Using .htaccess in PHP To Redirect Visitors To A Specified Page
Sometimes we can see some of the websites with messages like "Website under maintenance", "Our Trained Monkeys are working to fix the issues in the website, we will get back soon", "We are in work for upgrading our server please come back soon" and so on. I guess everyone would have seen those situations. But have you ever imagined how to add this to your website whenever you need such kind of work. Now let's do it.
Redirecting visitors to a maintenance page or other temporary page is an important tool for every webmaster or web developer. We can redirect the visitors to a maintenance page with a file called as ".htaccess", any ways we have to add some code in it. Now let's work on this how to redirect the visitors with .htaccess code.
Code For Redirecting all visitors with .htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteRule .* /maintenance.html [R=302,L]
Now that the .htaccess is in maintenance folder and also make a html page about saying that we are under maintenance , to the root directory of your site. This file can be just about anything like image ot text, and does not need to be written in HTML. You can use, say, PHP to make it all updations,
if u want to show this some of your clients only, then follow the below code, IN this code you can allow only specific ip address to see this page.By the by you can add multiple ip's or url as shown below
CODE :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^121\.256\.001\.000
RewriteCond %{REMOTE_ADDR} !^123\.256\.002\.000
RewriteCond %{REMOTE_ADDR} !^122\.255\.003\.000
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteRule .* /maintenance.html [R=302,L]
Now Get Practice this code and you can shout hurray...Enjoy friends