Redirect All Requests to Maintenance Page

  • follow us in feedly
Published March 21, 2013 by Brad Knutson
.htaccess Redirect

Using a place holder page, such as an “Under Construction” or “Maintenance” page, is a useful tool in any web developer belt. There are many different situations that would call for a global redirect of all requests to a domain to be sent somewhere else temporarily. Perhaps you are going through a rebranding of your product, facing legal trouble, or don’t want customers to see partial pages while you are making a large-scale platform upgrade or switch (for example, from WordPress to Drupal).

If you are using WordPress, there are several plugins that will give you this functionality. But what if you don’t want to bloat your WordPress install with another plugin, or perhaps your marketing department has given you a prebuilt “under construction” page that they want all requests to be redirected to, then you should be working in .htaccess.

If you are running on Apache, then a modified version of below code should be saved as your .htaccess file and uploaded to your web server in the public HTML directory.

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/placeholder.html
RewriteRule ^ /underconstruction.html [R=301]

The above code will redirect all requests to your domain, including stylesheets, images, javascript files, and more. You could code your placeholder page to have all inline styles, but what if you want to include images or scripts? Modify the code below to match your needs.

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/placeholder.html
RewriteCond %{REQUEST_URI} !=/path/to/style.css
RewriteCond %{REQUEST_URI} !=/path/to/script.js
RewriteCond %{REQUEST_URI} !=/path/to/image.png
RewriteRule ^ /underconstruction.html [R=301]

This is a very basic example, but you could easily get more creative with the rewrite conditions. Do you have a better rule to accomplish this? Leave a comment below!

The following two tabs change content below.
Founder at Inbounderish
Brad Knutson is a Web Developer in the Twin Cities area of Minnesota. He has experience working with WordPress and Drupal, and also has an interest in SEO and Inbound Marketing.

Keep Up-to-Date

Subscribe

Topics

See a complete list of topics discussed in blog posts here.

Check These Out

Get 2 Weeks Free! Sign Up Today! Premium Managed WordPress Hosting Genesis Framework for WordPress SEO is complex. Tools should be simple. Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

Share Your Thoughts

Your email address will not be shown.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">