How to Enable CloudFlare for Sub-Domains and Non-WWW Domains

cloudsWhen enabling CloudFlare through our hosting provider’s (Media Temple) built in integration a strange thing happened. The integration looked great and appeared to be setup correctly but we were only seeing a small trickle of pageviews reported by CloudFlare, one or two per day when we regularly get many thousands. Here is how to properly enable CloudFlare to service a website through Media Temple that uses a subdomain or does not use WWW to prefix the URL.

The key to this is that by default Media Temple, and other hosting providers with a direct integration to CloudFlare only provide a redirect through CloudFlare on www.yourdomain.com. If you normally use something like yourdomain.com or blog.yourdomain.com then the built in integration will be ineffective unless people (or robots) stumble across www.yourdomain.com. CloudFlare says that this is to preserve standards compliance.

This difference was discovered by running a tracert to both the root and www of our domain and they showed different paths with only www going to CloudFlare.

When a domain is activated via one of CloudFlare’s partner hosting providers, we’re unable to proxy traffic at the root (in order to remain RFC compliant). One simple work around to this is to modify the htaccess file on the web server to redirect traffic to the root to www which can be proxied by CloudFlare.

We weren’t interested in directing all traffic to www, though that surely would have worked, it would not help if the sub-domain has different content than the primary or root domain (like e-commerce vs. blog).

The first step is to un-register the CloudFlare integration with the hosting company. It’s best to wait until the hosting company shows this is complete, which can take up to 12 hours.

Next login to your CloudFlare account and add a new domain. Let CloudFlare scan your DNS records. It should show the root domain and any other sub-domains. If it doesn’t you’ll need to manually add the sub-domains that you want to run through CloudFlare.

Now CloudFlare will generate two nameserver entries. Go to your domain provider (may or may not be your hosting provider) and update the nameserver records that CloudFlare provides. Each domain that you add may be given different nameservers so make sure to note the exact instructions from CloudFlare.

Once the nameservers are changed CloudFlare click the button that says you’ve completed this task. CloudFlare will confirm that they see the changed with an automated email. This can happen nearly instantaneously or it may take several hours depending on your domain provider.

Now you’re all set and can change the settings in the CloudFlare dashboard to provide the services and protection that you want.

If you’re running WordPress also install the CloudFlare WordPress plugin and enter your API key and email address that are listed in the CloudFlare account tab.

Image: Flickr

Leave a comment

Your email address will not be published. Required fields are marked *