No www for subdomain

Apache Webserver
Apache Webserver

Earlier today i ran into a little problem with my .htaccess setup and a sub domain i created for habschned.com. In my .htaccess i use directives to redirect any incoming visitor that visits the page via habschned.com to www.habschned.com (done that for the sake of SEO). Now, the way the server is setup, sub domains would not work with www. prefixed (which happens automatically because of my .htaccess directives). So visiting http://photos.habschned.com would automatically redirect you to http://www.photos.habschned.com and result in a DNS failure as there is no NS entry for that address really.

If you should face the same problem then look no further for a solution. Here is what i have done to my .htaccess directives. Let’s look at the old one first, that did a pretty good job in terms of redirecting users/visitors as long as no sub domain was involved:

This needed some tweaking to make sure that sub domains are not gonna be prefixed with www and show error messages. So here is the rewrite rule in place now:

The above rewrite rule works just fine when it comes to stripping the www. part of the URL. You can test that by visiting http://photos.habschned.com/ which will be filled with content as soon as i have setup WordPress, NextGen Gallery and went through all the images i plan on posting there.

Be the first to comment

Leave a Reply

Your email address will not be published.


I confirm

*