How to Add a Maintenance Page Using the .htaccess File In WordPress
June 24th, 2017 | by Ravi Chahar || 2 Comments |
You may think about changing your web hosting or doing an overhaul of your website. At such point, you should know how to add a maintenance page using the .htaccess file.
It’s because you wouldn’t want your readers to see the changes you would be making. It shouldn’t be accessed by anyone else except you or the person doing these changes.
You may use a maintenance plugin to add a temporary page but while migrating your website to another web hosting, you can use the static page.
It can be created using the HTML codes.
I am going to walk you through a process to add the maintenance page using the cPanel of your web hosting account.
Start Adding the Maintenance File
First of all, you should create a static HTML page. For which, follow the steps.
Step 1: – Login to your cPanel account and open the file manager.
Step 2: – You have to create a new file using the option shown in the main navigation menu. Name that file as “maintenance.html” and saves.
It’s just a simple text file. You can create your own custom layout of the page using the HTML and style it the way you desire.
Once you save it, you have to redirect your visitors to this page.
Redirecting to the Maintenance Page
You have just created the static page. Now you have to make sure that only you or the person who is going to work on the website can access your website.
It can be done by restricting the access only to one IP address.
You have to add the code in the .htaccess file.
I hope you know how to edit the .htaccess file from the root directory of your website. As you’re already logged in the cPanel, you just need to find this file and open it for editing.
You can do it either using the Edit option from the menu or use the right-click.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^120.345.111.555
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
Add this code in the file.
NOTE: You have to replace the REMOTE_ADDR IP address to the IP address you want to have access with.
Once you do that, only the person with that particular IP address would be able to see the website. The rest would see a maintenance page.
You can design this page using the CSS easily. Just create something simple yet elegant to let people know that you’re bringing something beautiful to improve their experience.
This code is called the redirecting code.
Once you finish your maintenance work, you can either remove this code or add the # before every line of the code.
This will make every line a comment which wouldn’t work.
Isn’t That Easy to Add a Maintenance Page Using the .htaccess File
Though most of the people would like to add such page using a plugin still, you should know the alternatives.
It’s always recommended to provide the best possible user experience and while making any changes to your website, you should take care of that.
In the past few years, WordPress has evolved so much and you need to learn such technical things. I hope it wouldn’t be so hard to add a maintenance page using the .htaccess file.
If you still have any doubt, you can drop a comment. We will try my best to help you.
You can also connect with us on Twitter, LinkedIn, and Facebook.
Hello Ravi,
Thanks so much for sharing this article. here I have got a complete idea how to add a maintenance page via .htaccess file. If I need to shift my blog to another hosting, I can add a maintenance page myself, I don’t need to hire anyone to work on this.
This article will help many people who are not technically sound.
Thanks once again.
Moumita
Hi Ravi,
Great tutorial, it seems like every time I come to your blog, I learn something new. I had no clue that you could create a maintenance page for WordPress using the .htaccess file.
Whenever I’ve created maintenance pages in the past for clients, I have always used a plugin.
It’s nice to know that I can use the .htaccess file instead of uploading another plugin. Next time I need to create one, I am going to give this method a try.
Thanks for sharing this tutorial with us and I hope you have a great weekend ?
Susan