Moving WordPress to a Subdomain


Moving WordPress to a Subdomain

When you move a WordPress site to a subdomain, there are a few steps that can follow to ensure that the new subdomain will look and operate and you want. The steps are outlines below. 

1. Setup a new subdomain with cpanel or add an A record for the main domain.
2. Download the original database
3. Extract the database with a zip tool like Winrar, if necessary.
4. Open the database file in a text editor like Notepad++ or Gedit.
5. Do a search and replace for the old url and replace it with the new one. For example, search for http://example.com, http://www.example.com and replace this with your subdomain like newsubdomain.example.com
6. Do a search and replace for absolute paths like /home/username/public_html/example.com and change to the new path like  /home/username/public_html/newsubdomain.
7. You can look for hard coding in files too. Your editor can do a find / replace for all files or you can use the Linux command line. The command 'grep -H -r "www.example.com"  /home/username/public_html/newsubdomain' will serach the new subdomain for www.example.com.
8. Create a new database and dump (import) the updated '.sql' file.
9. Change the database settings in wp-config.php.

At this point, you can open the new subdomain and see the website. It may or may not look exactly as you expect. One issue could be that the header is missing files. This can be fixed. Open the original domain and find the header image name with 'View Source'.  Do a find and replace in the database using phpmyadmin (or command line). The url for a subdomain will change in size. Believe it or not, the size is important.

If the url grew by 13 characters (example.com became newsubdomain@example.com), you can change numbers like 's:55' to new amount of characters. For example, in wp_options you may have an option_name like theme_mods_templatename where 's:55' needs to be changed to to new amount of characters for the long absolute url lengths. Essentially, all instances of 's:55' will now become 's:68'.

Now, the website should display properly.