Moving a WordPress install to a subdomain

Hi kids! Today we’re going to learn about moving WordPress to a subdomain. Why would you want to do that? Well, let’s say that you want to have SSL over the subdomain (only), or that you want the subdomain to be an internal address that no one else can access. This became an issue for me when I decided to transition to the CloudFlare infrastructure, which supports SSL on a domain only if you pay them. I am way too cheap for that.

The obvious thing to do is to go into General Settings (/wp-admin/options-general.php) and modify the “WordPress address” to add the new subdomain. For example, mine originally read https://dustin.li/word/, but now reads https://secure.dustin.li/word/. After clearing caches, the Log In link on the blog now correctly directs to the secure subdomain for login, and I am able to see the administration dashboard on the subdomain. There is a problem, however: the public site does not reflect that you are logged in! This means that your users will not be able to use any features of being logged in, and you will not see the administrative features on the public site.

There is an easy fix for this, though. In your wp-config.php file, add a line like this:

define(‘COOKIE_DOMAIN’, ‘.dustin.li’);

This tells WordPress that your cookie should be set and read in the “.dustin.li” domain, which any of the subdomains in dustin.li (including secure.dustin.li and dustin.li itself) can read. Problem solved! Huzzah!

This entry was posted in Pub. Bookmark the permalink.

Leave a Reply

Your email address will not be published.