Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to temporarily redirect all requests for a site to index.html, using Apache only. Is this mod_rewrite approach going to work, and is it the right way to do it?

RewriteEngine on
RewriteRule   ^.*$  /index.html  [R]
share|improve this question
I think you should use [R=302] to specify it is temporary. – pritaeas Jan 24 '11 at 16:02
@pritaeas Note that R and R=302 are the same. Apache defaults to a 302 unless stated otherwise. – w3dk Oct 31 '15 at 19:08
up vote 1 down vote accepted

You need to use something like this I think:

RewriteRule !^/index.html$  /index.html [R=302]

Like pritaeas noted, you should use the 302 code to specify that the move is temporary. And you want to match everything but /index.html, otherwise you'll send the browser on an infinite redirect loop.

Also, if you have any images, stylesheets, JS files, or other resources that are in the same directory or subdirectory, you need to also make exceptions for those or turn the rewrite engine off in those directories.

share|improve this answer
Thanks, that's really helpful. – jaybee Jan 28 '11 at 18:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.