I recently purchased a new domain for my WordPress site and I want to redirect anyone who visits using an old domain to the new one. I haven’t moved servers, just added a new domain.
For instance, if they went to either of these:
http://www.example.net/some-article/
http://example.net/some-article/
Then I’d like them to be redirected to the appropriate URL:
http://www.example.com/some-article/
http://example.com/some-article/
How would you do this simple .net -> .com redirect with a .htaccess file? Any rule should apply to all URLs under the .net domain.
Thanks in advance.
Edit: I already have the .htaccess file on the server:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AddHandler php5-script .php
You need to add commands like this to your .htaccess file:
redirect permanent /some-article/ http://www.example.com/some-article/
Is this a server with mod_rewrite? In this case you could do a generic redirection for all paths:
I would modify your existing rewrite block to look like this:
Note that I haven’t actually tested this…
REMOTE_HOST
may also work instead ofHTTP_HOST
. The mod_rewrite documentation recommends usingHTTP_HOST
, although this will not work if the brower only understands HTTP/1.0I converted from Drupal to WordPress a while ago, and I ended up spending a bunch of time trying to get these redirects to work properly. My big hangup was figuring out how to use RewriteCond in conjunction with RewriteRule. Here’s an excerpt from an article I wrote about this:
It’s also really helpful to keep an eye on inbound hits and links to see if anyone is using an old form of URL that you’re not translating yet. I had an inbound link that was encoded as a PostNuke URL (from two blog platforms ago!), and this technique made it really easy to fix.
Here’s a link to my article, btw: Use .htaccess to redirect from Drupal to WordPress
old Domain: RewriteCond %{HTTP_HOST} !^abcd.com$ [NC]
New Domain: RewriteRule ^(.*)$ http://abcdef.com/$1 [R=301,L]
I bet if you put this at your old domain and simply change the second line to your new use your new domain, it would work.