I was asked by a client to temporarily shutdown his website and display an under maintenance mode page. Now if this was a wordpress site then it would have been a piece a cake. I would have just installed a maintenance plugin and activated it and all the pages would have been redirected to the maintenance mode page.
But this was an html site. And at first thought, you would think that you could just upload a new index.html page that has some text on it that says the site is currently under maintenance. But the problem with that is that you can still access all the internal pages.
Another option would have been to move all the files and pages into a new folder or zipped folder so there is no trace of the original pages. This creates a problem also. Your pages could get de-indexed from the search engines and it would take some time to get them indexed again when the site goes back up.
So I wanted to just change the .htaccess file to redirect all the pages to a specific one. There are a lot of htaccess codes out there that say this is the code that does that but most of them don’t work to redirect all pages. So here is the correct code to place in your .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.html
RewriteRule .* /index.html
Where is says “/index.html”, you would place whatever page or url you want all your pages to redirect to.
Now this is not a 301 redirect which transfers all link juice to a new domain name so if that is what you are looking for then this is not that.
Hope this helps in what you were looking for.
Thanks all for the tips. I forgot that I could do this via cPanel, which creates the redirect in .htaccess automatically. So, this is what I got now.