Viewing entries in
Wordpress

How to Redirect all Wordpress links to a new domain name

Today I changed the name of my website from www.quantumpie.com to www.dancingphysicist.com. I did not want to set up a new installation of Wordpress and import all of my old posts, rather I just wanted to change the name of my site. The problem is that I needed a way to have all of my old Quantumpie.com pages to redirect to the dancingphysicist.com page. For example, www.quantumpie.com/about should automatically send a visitor to www.dancingphysicist.com/about. I also wanted to make sure that search engines, like Google, knew that quantumpie.com was no longer active and their results should be transferred to the equivalent www.dancingphysicist.com page.

Changing the name of a Wordpress site

On your web host Make sure that the new domain name is linked to the directory containing your Wordpress site. In my case, both quantumpie.com and dancingphysicist.com pointed to the same directory. Using either your old or new domain name it should be possible to reach your site.

Redirecting links from the old domain to the new domain

To redirect all of you old links to the new site you must modify the .htaccess file in the root directory of your Wordpress install. If your web host has enabled "mod rewrite" capabilities, then all you need to do is add the following code before the Wordpress section of the file:

[shell] 
# Redirect the site 
RewriteEngine On 
# Take care of www.quantumpie.com 
RewriteCond %{HTTP_HOST} ^www.quantumpie.com$ [NC] 
RewriteRule ^(.*)$ http://192.241.200.187/$1 [L,R=301]

# Takes care of quantumpie.com 
RewriteCond %{HTTP_HOST} ^quantumpie.com$ [NC] 
RewriteRule ^(.*)$ http://192.241.200.187/$1 [L,R=301]

# Below is the standard code Wordpress uses 
# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
[/shell]

Change www.quantumpie.com and quantumpie.com to your old domain name, and www.dancingphysicist.com to your new domain name. The first line of the code:

RewriteEngine On

enables the URL rewrite module that we need. The next line:

RewriteCond %{HTTP_HOST} ^www.quantumpie.com$ [NC]

says that if anyone requests a page from www.quantumpie.com then perform the rule on the next line. This rule is:

RewriteRule ^(.*)$ http://192.241.200.187/$1

and it redirects the page to the equivalent page on www.dancingphysicist.com. The (.\*) means any text in the URL after www.quantumpie.com, and the $1 at the end of www.dancingphysicist.com/ is a variable that tells the web server to place the text from (.\*) after it. Now any website that calls a link like http://www.quantumpie.com/example-link will now redirect to http://192.241.200.187/example-link

 

The [L,R=301] at the end of the rule is a 301 redirect that tells any search engine or bookmark software that this is the new, permanent, home of the link and that they should update their records accordingly.

The next few lines are nearly the same and redirect all calls from http://quantumpie.com to http://www.dancingphysicist.com.

Changing your site information in Wordpress

Once I verified that the redirects were working, I logged into my Wordpress admin panel and went to "Settings->General" where I entered in the new Site Name, Wordpress URL, and Site URL. Make sure you change change both the Wordpress URL and Site URL before saving. If you don't, this can cause an error. If things mess up, you can follow these instructions to fix things if you have FTP access to your site.

Alerting Google

I logged into Google Webmaster tools and Google Analytics and changed the name of my site from quantumpie.com to dancingphysicist.com. All of my analytics and information smoothly transitioned over.

Following these steps it was relatively painless to rename my site without losing any of my old posts or creating duplicate content.