Migrating Website To New Domain Name
After days, months or years, you have finally come to the conclusion that you want to migrate your website to a new domain name. There are many reasons why you may want to do this such re-branding, recycling content, you need a name that reflects how the website has grown or you want to use a ‘new domain name’ that is easier to remember. Now that you have the plan, you must execute it. The move is rather quite simple and this procedure will work for any small or large php / mySQL website whether it was made with WordPress, Joomla, or a custom php / mySQL script. The process consists of five simple steps. The steps are to change the old domain name to the new one in all files, make the same name changes in the database, alter your database connection settings (if necessary), add a 301 redirect and resubmit new sitemaps.
1. File Name Changes
The first step is to do a ‘Find’ and ‘Replace’ for all occurrences of your old domain name in your files and replace it with the new domain name.
One way to do this is to ftp the files to your pc and use an editor that can search all files and folders for a specific string and replace it with the new one. For example, you search for example.com and replace it with example.net. In many cases, you can change everything at once. But, if you have large error_log files or lots of cache files it could take a while. You could remove all error_log files and cache files to save time, if necessary.
If you have Linux shell access, you can do a quick find and replace with the Linux command line. The example below will find and replace a string for all files within the directory. The example below will search for example.net and replace it with example.com. Be careful! If you screw up, you screw each occurrence up and need to fix it. However, this example shows hows effective command-lining can be.
root# grep -rl ‘example\.net’ /home/username | xargs sed -i ‘s/example\.net/example\.com/g’
2. Database Name Changes
Changing the occurrence of your old domain to the new one is simple. You download an uncompressed sql file and load it in an editor. Then, you do a simple find for the old domain name and replace it with the new one. After that, you can import that database into a new or existing database.
3. Alter Database Connection
If you setup up a new database on a new account or a new host, you will have a different. You must change the old username and password with the new one. If you try to view web pages with invalid credentials, your browser will show you connection errors.
4. Add a 301 in your .htaccess File
The one line below can be added to your .htaccess file so that all old urls will point to the new ones. In other words, example.net will redirect to example.com and pages like example.net/wordpress_post will redirect to example.com/wordpress_post.
Redirect 301 / http://example.com/
5. Resubmit a New Sitemap to Google Webmaster Tools
Finally, login to your Google Webmaster Tools account and submit new sitemaps for the new domain.
Out with the old, in with the new. All of your web pages that are indexed with Google (or any other search engine) will redirect to your new website. In time, your new content and old pages on the new website will be indexed. All in all, everything will go smoothly as though the move did not take place.