Apache .htaccess Rewrite CDN / Parallel Subdomains Drupal CDN

Author:
phil
Created:
Sunday, November 27th, 2011
Last Updated:
Wednesday, October 02nd, 2019

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


First off, I suck at programming... secondly, I suck at apache rewrite rules because it's basically programming. It took me a while to come up with a no-nonsense method to rewrite my parallel / cdn subdomain names, so I wouldn't get hassled by the search engines because it looked like I had all sorts of duplicate content being served from my cdn subdomains.

I say "cdn" subdomains because that's what I searched on forever until I realized I wasn't truly doing content delivery network or content distribution network (CDN), I was simply doing parallel downloads. Yeah, I feel stupid, don't nark on me... :p

The main reason I got so confused is because Drupal has a module called CDN that will do parallel downloads, but it will also do a lot of fun stuff with actual CDN's too.

Moving on, I wanted to share the page that got me started, but also share the RewriteRule I enabled on my site which seems to be working pretty good at this point:

RewriteCond %{HTTP_HOST} ^srv(1|2|3)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|swf|png|gif|jpe?g|pdf|gz|zip)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R]

srv(1|2|3)\.example.com being:
srv1.example.com
srv2.example.com
srv3.example.com

Post Comment