Awesome .htaccess Trick for Redirecting All Traffic When Working on a Site

by Bradley on August 20, 2010

I usually don’t do posts that include code, but this trick it just too cool.

The code below is for your .htaccess file.  You would want to use this whenever you are working on a site and you want to redirect the site elsewhere while you are working on it.

So, in this case we duplicated the site on a subdomain while we worked on the main site.  Then we put in these redirects to direct everyone looking for the home page & anyone who reached a 404 page to be redirected.

What’s great about this is that you can still work on your site as long as you know the right URL for the page you are looking for.

# TEMPORARY REDIRECT
redirect 302 /index.html http://youwantthemtogohere.com
ErrorDocument 404 http://youwantthemtogohere.com
Just replace what’s in your .htaccess with the code above and you’ll be fine.
Of course, this works in WordPress too, so worry not!

Want More out of WordPress?

I can show you how to get more traffic, make WordPress do amazing things, and how to make more money with your website by converting your visitors into customers. Click the button to the right to get a free estimate.

  • http://cleverwp.com/ Lars Koudal

    Hi Bradley, nice trick, I like it :-)

  • nev

    Trouble with this is, anyone “landing” on a page other than index.html will still see the page, with all the reconfiguration going on – unless you really mean ‘subdomain’, as in redirecting to (say) http://testing.example.com as opposed to the “original” http://www.example.com

    • http://www.belvini.de chris wein

      Ha! exactly that was my first thought, what about visitors come from external deeplinks…

      but anyway, very great site – love wordpress seo-results, too. but its codebase is still UGLY :-)
      cheers
      chris

      • Bradley

        Yeah, it doesn’t work for deep links. More of a quick and diryt fix.

Previous post:

Next post: