Moving wordpress to another host

If you’ve been following my blog for awhile, you might have noticed I moved this blog from www.theodorenguyen-cao.com to theodorenguyen-cao.com as it was more fitting domain. I originally just registered the domain, added the DNS record, and updated my apache config to have theodorenguyen-cao.com to be an server alias to www.theodorenguyen-cao.com.

This allowed requests to www.theodorenguyen-cao.com/* and theodorenguyen-cao/* respond with the same content. I thought I was done. I discovered this wasn’t the case when I saw www.theodorenguyen-cao.com as a direct traffic source in my google analytics for theodorenguyen-cao.com. To fix the screwed up analytics, I needed to make it so that all requests that go to www.theodorenguyen-cao.com are permanently redirected (301) to theodorenguyen-cao.com.

To do this I had to apply an Apache mod_alias redirect directive as such:

<VirtualHost *:80>
        VirtualDocumentRoot /var/www/blog
        ServerName www.theodorenguyen-cao.com
        Redirect permanent / https://www.theodorenguyen-cao.com/
        ErrorLog /var/log/apache2/wp-error.log
        TransferLog /var/log/apache2/wp-access.log
</VirtualHost>

The virtual host for theodorenguyen-cao.com looks like:

<VirtualHost *:80>
    VirtualDocumentRoot /var/www/blog
    ServerName www.theodorenguyen-cao.com
    ServerAlias theodorenguyen-cao.com
    CustomLog /var/log/apache2/theodorenguyen-cao.com_access.log Combined
    ErrorLog /var/log/apache2/theodorenguyen-cao_error.log
</VirtualHost>

At first I thought this would only fix the simple case of www.theodorenguyen-cao.com redirecting to theodorenguyen-cao.com, but blog.notepath.com/foobar not being translated to theodorenguyen-cao.com/foobar. However, this does exactly what I want. All www.theodorenguyen-cao.com URLs will be replaced with theodorenguyen-cao.com URLs. Old bookmarks will simply redirect to a theodorenguyen-cao.com URL and not 404.

Success!

I’m still waiting to see if Google will update the search result links that point to www.theodorenguyen-cao.com to be theodorenguyen-cao.com URLs.

Moving wordpress to another host