Say I own "" and I want everyone typing in "" to be directed to ""

However, if someone types in "", I don't want it to be redirected to ""

Is this achievable by a set of rewrite conditions and rules?

2 answers

Doug 1095
This was chosen as the best answer
RewriteEngine on
RewriteRule ^$ [R=301,L]

(Found here)

Answered about 7 years ago by Doug
  • That was surprisingly simple. wow. Thanks! Andy Zhang about 7 years ago
  • Yeah, I tried several more complicated schemes before finding that one. Happy New Year! Doug about 7 years ago
Doug 1095

It probably can be done in .htaccess; I can look into it if necessary. But a much easier method is to use PHP. I've done this exact same thing on a site I worked on recently.

Create a file called index.php in the root directory of with only this in it:


"301" means "Moved Permanently". Use "307" for a "Temporary Redirect". Whether you use 301 or 307 will affect how search engines and browsers treat that link in the future.

Answered about 7 years ago by Doug
  • Yes, that's exactly how it is set up right now =] However, that requires the PHP engine to process this tiny thing every time instead of Apache taking care of it as soon as the visitor reaches the server. It does add up once lots of visitors arrive from digg and the sorts. A .htaccess method would be much appreciated! Andy Zhang about 7 years ago
  • Out of curiosity, have you noticed slowdowns in the past because of this? Doug about 7 years ago