Web:  

24May

Wildcard DNS and Sub Domains

Internet

What follows is what I consider to be best practice for my personal sites and a guide for those who wish to do the same. Months ago I dropped the www. prefix from my domain in part because I think it’s redundant and also because I wanted to experiment with how Google treated valid HTTP redirect codes. The experiment has been a great success. Google seems to fully respect 301 Permanent Redirects and the change has taken my previously split PageRank has been combined and now I am at 7. There are other factors that have contributed to this, of course, and people still continue to link to my site and posts with a www. (or worse) in front of it, but overall it just feels so much cleaner to have one URI for one resource, all the time. I’m sure that’s the wrong way to say that, but the feeling is there nonetheless.

Now for the meat. What’s a good way to do this? Let’s look at our goals:

  • No links should break.
  • Visitors should be redirected using a permanent redirect, HTTP code 301, meaning that the address bar should update and intelligent user agents may change a stored URI
  • It should be transparent to the user.
  • It should also work for mistyped “sub domains” such as ww. or wwww. (I still get hits from Carrie’s bad link)

So we need a little magic in DNS and in our web server. In my case these are Bind and Apache. I am writing about this because at some point the code I put in to catch any subdomain stopped working and while I reimplemented it I decided to write about what I was doing. This method also works with virtual hosts on shared IPs where my previous method did not.

In Bind you need to set up a wildcard entry to catch anything that a misguided user or bad typist might enter in front of your domain name. Just like when searching or using regular expressions you use an asterisk (or splat) to match any number of any characters the same thing applies in Bind. So at the end of my zone DB file (/var/named/photomatt.net.db) I added the following line:

*.centutz.com. 14400 IN A 64.246.62.114

Note the period after my domain. The IP is my shared IP address. That’s all you need, now restart bind. (For me /etc/init.d/named restart.)

Now you need to set up Apache to respond to requests on any hostname under photomatt.net. Before I just used the convinence of having a dedicated IP for this site and having the redirect VirtualHost entry occur first in my httpd.conf file. That works, but I have a better solution now. So we want to tell Apache to respond to any request on any subdomain (that does not already have an existing subdomain entry) and redirect it to photomatt.net. Here’s what I have:

<VirtualHost 64.246.62.114>
DocumentRoot /home/photomat/public_html
BytesLog domlogs/centutz.com-bytes_log
User centutz
Group centutz
ServerAlias *.centutz.com
ServerName www.centutz.com
CustomLog domlogs/centutz.cm combined
RedirectMatch 301 (.*) http://centutz.com$1
</VirtualHost>

The two magic lines are the ServerAlias directive which is self explanitory and the RedirectMatch line which redirects all requests to photomatt.net in a permanent manner.

There is a catch though. The redirecting VirtualHost entry must come after any valid subdomain VirtualHost entries you may have, for example I have one for cvs.photomatt.net and I had to move that entry up in the httpd.conf because Apache just moves down that file and uses the first one it comes to that matches, so the wildcard should be last.

That is it, I’m open to comments and suggestions for improvement.

 

No comments

Saturday, May 24th, 2008 at 9:13 am and is filed under Internet. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Centutz

ClickLink.ro http://www.adaugasite.info// Blog Resources Blogs - BlogCatalog Blog Directory
agende | andrei stanciu | promovare online | brelocuri | brichete | brichete personalizate | cadouri 1 martie | cadouri 8 martie | cadouri craciun | cadouri mos craciun | cadouri online | cadouri paste | cadouri personalizate | cadouri sfantul valentin | cadouri sf valentin | calendare | calendare de birou | calendare de perete | cani personalizate | ceasuri de mana | ceasuri de perete | coperta meniu | cheap dedicated servers | firme companii | gravura laser | hotel restaurant | matrimoniale | mape meniu | marochinarie | meniuri restaurant | odorizante auto | anunturi gratuite | pixuri | pixuri personalizate | plangeri | pliante | produse promotionale | productie publicitara | promotii online | servere dedicate | tampografie | perdele | covoare | draperii | decoratiuni interioare | lenjerii pat | fete de masa | brelocuri piele | brelocuri metal | brelocuri plastic | brelocuri cauciuc | brelocuri auto | brelocuri hotel | agende a4 | agende a5 | agende a6 | agende de birou | agende policromie | meniuri a4 | meniuri a5 | note de plata | semn masa rezervat | suport pahar | suport masa rezervat | meniuri piele naturala | meniuri piele sintetica | web design | realizare pagini web | agende datate | agende nedatate | personalizare agende | brichete cu desfacator | brichete piezo | brichete metalice | brichete cu lanterna | brichete cu toc | calendare de perete | calendare de birou | calendare triptice | calendare cu flori | calendare cu peisaje | calendare cu manastiri | calendare cu orase | calendare erotica | calendare cu masini | brichete cu protectie pentru copii | CeMap | CeMap Training london | CeMap Courses | CeMap Training in London | CeMap Test | CeMap London | pixuri Tibi | pixuri Luxor | pixuri Grand | pixuri Span | pixuri Rio | pixuri Forte | pixuri York | pixuri Bian | pixuri Neo | pixuri Vito | personalizare pixuri | pixuri metalice | pixuri din plastic | pixuri Viva | brichete unilite | volumetrie 3d | gravura mecanica | personalizari auto | felicitari calendare | personalizari textile | mortgage test | mortgage training in uk | mortgage advisor in uk | mortgage broker in uk | cemap training in uk | mortgage advisor | mortgage broker | mortgage training | cemap training | Download Muzica Noua Gratis | Movies, Torrents, Trailers | Centutz | Mu Romania | Scams Alert-Report Here Your Complaints, Scams | Unic Blog - Create your Free Blog Now | Little Upload - Image Hosting and Image Upload | Tricks and Tips | Warez - Full And Free Nulled Scripts | Funny Images | Anunturi Automobile Gratuite | Bocanci, Casti De Protectie | Echipamente De Protectie | Manusi, Imbracaminte De Protectie | Ochelari, Incaltaminte De Protectie | Protectia Munci | Salopete, Cizme De Protectie | Semne De Circulatie | Truse De Prim Ajutor | The Business Development Academy | Echipamente de Protectie | The Financial Training Academy at blogster.com | | The Financial Training Academy at studioathome | The Financial Training Academy at grab.com | The Financial Training Academy at blogspot.com | The Financial Training Academy at aol | The Financial Training Academy at multiply | The Financial Training Academy at 20six.co.uk | The Financial Training Academy at blogsome | The Financial Training Academy at xanga | The Financial Training Academy at geocities | The Financial Training Academy at freewebs | The Financial Training Academy at opendiary | The Financial Training Academy at bravejournal | The Financial Training Academy at mydeardiary.com | The Financial Training Academy at blog.co.uk | The Financial Training Academy at outblogger.com | The Financial Training Academy at clearblogs.com | The Financial Training Academy at ebloggy.com | The Financial Training Academy at blogs.ie | The Financial Training Academy at teenblog.org | The Financial Training Academy at egoweblog.com | The Financial Training Academy at blogbeee.com | The Financial Training Academy at livejournal.com | The Financial Training Academy Ltd | Jonathan Russo | The Financial Training Academy | The Financial Traning Academy LTD Group | Fta-Academy-Ltd-Site-About-U | The Financial Training Academy Home | The Finacial Training Academy LTD Home | the-Financial-Training-Academy-ltd-Corporation-Home | The-Financial-Training-Academy-LTD-Group-Home | The Financial Training Academy LTD Shop | The Financial Training Academy LTD Site | The Financial Training Academy LTD Test |
Yahoo! Messenger Spy Director web Adauga-site.eu add-url Director web Director Web adirector Business Portal Boxlinks - Linkuri utile CEVAceCAUTI.ro 2AddLink Web Link Directory AAAWebDirectory.com A Big Dir All Direct Links AllURLs Link Directory Anaximander Directory Listed in Web Design Directory from Apexoo AZ Links Directory Click2Directory - A FREE Website Listing Directory Service Click my Brick Directory Anaximander Directory Web Directory Directory 4U Free East Web Directory Findsome.info Directory Technorati Profile Add to Technorati Favorites Free links Directory Free Website Directory Good Directory Helpful.ws - Web Search HyperLiNK - SEO Friendly Directory Review Centutz - The Official WebSite Junglefinder Directory King of the web Link On Up Nice Directory LinkDirectory izZy Music elitescriptz.com MuRomania