I lately bought a brand new domain for my WordPress site and I wish to redirect anybody who visits utilizing an old domain towards the brand new one. I've not moved servers, just added a brand new domain.

For example, when they visited either of those:

http://www.example.net/some-article/
http://example.net/some-article/

Then I would like these to be rerouted towards the appropriate URL:

http://www.example.com/some-article/
http://example.com/some-article/

How does one do that simple .internet -> .com redirect having a .htaccess file? Any rule should affect all Web addresses underneath the .internet domain.

Thanks ahead of time.


Edit: I curently have the .htaccess file around 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 have to add instructions such as this for your .htaccess file:

redirect permanent /some-article/ http://www.example.com/some-article/

Is a server with mod_rewrite? Within this situation you can perform a generic redirection for those pathways:

RewriteEngine On

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]

I'd modify your overall rewrite block to appear such as this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# New code to redirect from example.net to example.com
# Permanent redirect for caching purposes, also include the query string
RewriteCond %{HTTP_HOST} ^example\.net
RewriteRule (.*) http://example.com/$1 [R=permanent,QSA,L]

# New code to redirect from www.example.net to www.example.com
RewriteCond %{HTTP_HOST} ^www\.example\.net
RewriteRule (.*) http://www.example.com/$1 [R=permanent,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

AddHandler php5-script .php

Observe that I've not really examined this...

REMOTE_HOST could also work rather than HTTP_HOST. The mod_rewrite documentation suggests using HTTP_HOST, even though this won't work when the brower only knows HTTP/1.

I converted from Drupal to WordPress not long ago, and that i wound up investing a lot of time looking to get these redirects to operate correctly. My large hangup was determining using RewriteCond along with RewriteRule. Here's an excerpt from articles I authored relating to this:


# Rewrite drupal urls to worpress
RewriteCond %{QUERY_STRING} ^q=node/(.+)$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?p=%1 [R=301,L]

# Forward RSS feed
RewriteCond %{QUERY_STRING} ^q=rss.xml$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?feed=rss2 [R=301,L]
RewriteCond %{QUERY_STRING} ^q=atom/feed$
RewriteRule ^(.*)$ http://blog.componentoriented.com/?feed=rss2 [R=301,L]

It is also really useful to keep close track of inbound hits and links to ascertain if anybody is applying a classic type of URL that you are not converting yet. I'd an inbound link which was encoded like a PostNuke URL (from two blog platforms ago!), which technique managed to get quite simple to repair.

Here is a connect to my article, btw: Use .htaccess to redirect from Drupal to Wordpress