Server Fault is a question and answer site for system and network administrators. 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 have found a number of different solutions of what should be written in the .htaccess file but for some reason they don't work perfectly.

I would like to redirect all content from old site to go to the new site - to redirect to

and so on. I have heard that this is the correct way to redirect permanently when moving a site from one domain to another in respect to SEO, so that search engines do not doublicate the content and penalize for it.

So if anyone can provide working code, that would be great. Explanations on why that would work and what things in it mean would be in the awesomeness category.

thanx a bunch.

PS, i have mod_rewrite enabled already.

share|improve this question

I highly suggest John Gruber's Using .htaccess Redirection to Standardize Web Server Addresses. The "GETTING RID OF ‘WWW’ PREFIXES" section gives a straightforward example of the simple rewrite you need along with a clear explanation.

You can substitute www\.oldsite\.com for www\.daringfireball\.net and for, respectively, in his example, giving you the following:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
RewriteRule (.*)$1 [R=Permanent]

Or, in the "REDIRECTING FROM ‘.COM’ TO ‘.NET’" section, he explains how to use mod_alias to do exactly what you're asking for, as follows:

RedirectMatch permanent (.*)$1

His article is a great overview of both methods and gives you the knowledge to pick whichever works best (obviously mod_alias is the shorter implementation, but mod_rewrite tends to be the more flexible in the long run, in my opinion). He also links to Dave Child's excellent mod_rewrite Cheat Sheet.

share|improve this answer
hi, i used those. the main domain redirects. but if i type does not take me to – mgPePe Jul 21 '11 at 12:12
So -> works, but not -> Which method did you use, mod_rewrite (RewriteCond + ReWriteRule) or mod_alias (RedirectMatch)? Is there anything else in your .htaccess file? – morgant Jul 21 '11 at 15:50

Create a .htaccess file with the code given below. It will ensure that all the directories and pages on your old domain will correctly redirect to your new domain. The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymLinks
# RewriteEngine on - You have this enabled already, so this is not required.
RewriteRule (.*)$1 [R=301,L]

Please REPLACE in the above code with your actual domain name.

share|improve this answer

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.