Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a WordPress blog running on an Apache2 server currently that I need to completely move to a new domain name.

http://www.somesite.com/ to http://www.someothersite.com

I need all requests to that domain to be redirected to a new domain name. Can this be done with .htaccess? If so what's the rule to be used?

share|improve this question
add comment

3 Answers

If URLs are exactly the same and the only difference is the domain name, then it is very easy to do. Just place this line in .htaccess in website root folder of www.somesite.com:

Redirect 301 / http://www.someothersite.com/

The above rule will redirect (301 Permanent Redirect) ALL requests to a new domain using the same URL and preserving the query string.

At the same time you may need to disable any existing rewrite rules in that .htaccess file, otherwise WordPress may be processing all rules before such redirect occurs (RewriteRule has higher priority than Redirect).

share|improve this answer
add comment

LazyOne beat me to it :) .... So what he said.... PLUS:

In the Wordpress Dashboard you have to find the setting where you put the domain name of your blog and change it to the new domain name. Otherwise, most links will point to the old domain.... which of course get directed back but it will obviously be inefficient.

share|improve this answer
add comment

The simplest way is to use a 301 redirect in a .htaccess file on the old domain which will point to the new domain. Use the following code:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Rememer to change www.newdomain.com to your actual new domain name. This code is dependant on mod_rewrite being installed in the Apache server. It usually is.

Another alternative is to use Rewritematch e.g.

RedirectMatch 301 (.*) http://www.abookaboutchina.com/$1
share|improve this answer
    
I recommend you to DOUBLE CHECK your facts BEFORE making such statements -- if in doubt -- consult Apache documentation‌​. Start with this link: When NOT to use mod_rewrite. P.S. I'm not going to -1 you -- technically rule is correct -- the explanation is wrong. –  LazyOne Jul 25 '11 at 8:48
add comment

Your Answer

 
discard

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.