by Ryan Walker

Easy canonical URLs in Apache

This domain was previously pointed to http://rywalker.mp; Google now has old www.rywalker.com references from that era. It’s bugging me, so I want to try to clear it up in the future by having a no-www canonical URLs for this site.

Before:

<VirtualHost *:80>
  ServerName rywalker.com
  ServerAlias www.rywalker.com
  DocumentRoot /home/deploy/apps/rywalker/nesta/public
</VirtualHost>

During my research, I discovered that there is a duplicate content myth circulating, and I did wonder if Google would love me more if I wasn’t tossing duplicate content out there with my server alias.

After:

<VirtualHost *:80>
  ServerName rywalker.com
  DocumentRoot /home/deploy/apps/rywalker/nesta/public
</VirtualHost>

<VirtualHost *:80>
  ServerName www.rywalker.com
  RedirectMatch 301 ^(.*)$ http://rywalker.com$1
</VirtualHost>

Simple enough, hopefully my clarity goes rewarded by our search engine overlords. And if nothing else, I’ll be happy to see the www.rywalker.com references disappear from search results over time.