Holt
|
|
Master of Style
|
   
|
|
|
Reged: 05/15/03
|
|
Posts: 1244
|
|
Loc: Trussville, AL
|
|
Wildcard DNS
#13456 - 10/19/06 11:17 AM (216.104.80.203)
|
|
|
One great feature available from some web hosting services is Wildcard DNS. This means that any url that ends with your domain name will hit your web site. For instance, eq.doaguild.com, www.doaguild.com, and dickshatband.doaguild.com will all hit the DOA site.
When it hits the website, any of those urls will invoke the default web page (usually index.html). To display different pages based on what name is used to reach your site, you can use SSI (server side includes). You can probably use some feature of ASP to achieve the same end, but that's a Microsoft abomination and we shall not speak of it again.
HTML files that contain SSI commands are typically identified by the extention shtml or htmls. SSI and the correct extention are enabled/defined by your web hosting company. The magic part of SSI that helps us with Wildcard DNS is HTTP_HOST. This contains the name used to access your website. Here is a sample index.shtml file for handling Wildcard DNS:
Quote:
<!--#if expr="${HTTP_HOST} = /one.doaguild.com/" --> <!--#include file="one.html"--> <!--#elif expr="${HTTP_HOST} = /two.doaguild.com/" --> <!--#include virtual="cgi-bin/two.cgi"--> <!--#else --> <!--#include file="default.html"--> <!--#endif -->
A couple of things to look at in that sample. First "#include file" simply pulls in the specified file from the websites default directory and displays it to the user. "#include virtual" will do the same for files located in another directory. Also note that in this case the virtual include is puling in a cgi file. This file will be executed on the web server and it's output sent to the user. You can include as many #elif sections as needed to handle different names. You really need the #else on the end in case someone hits your site with a name you are not expecting.
Looking back at the cgi file, that program may need to know what name the user hit the website with. For instance, if the cgi program displays a screen with a link to go back to the home page, you would want to return to the correct page. The environment passed to the cgi program includes a variable called SERVER_NAME. It will contain the base part of the name used to access the website, for example: eq2.doaguild.com. If your cgi program were written in perl, you could display this name with this short program:
Quote:
print "Content-type: text/html\n\n"; print "<html>\n"; print "<head> <title>Server Name</title> </head>\n"; print "<body>\n"; print "<p>$ENV{SERVER_NAME}</p>"; print "</body>"; print "</html>";
If you are not using perl, you will need to use whatever facilities are provided to access the program environment (getenv in c or php for example).
Using SSI and Wildcard DNS you can make your website much more versatile, easier for users, and give it a more professional look.
-------------------- No, I don't mind being the smartest man in the world. I just wish it wasn't this one.
Post Extras:
|
|
Anskiere
|
|
Cheese God of DOA
|
 
|
|
|
Reged: 06/23/03
|
|
Posts: 773
|
|
|
|
|
If you have access to the apache config for your host you can also configure separate virtual hosts with independent document roots so the pages themselves don't have to include any site-specific logic. But I'm guessing most non-dedicated hosting services don't offer that level of control.
Post Extras:
|
Holt
|
|
Master of Style
|
   
|
|
|
Reged: 05/15/03
|
|
Posts: 1244
|
|
Loc: Trussville, AL
|
|
|
Actually phpwebhosting does (indirectly through their control panel). But it doesn't establish a cgi-bin for each virtual site... Still, if you have alot of "html" or "shtml" pages...
-------------------- No, I don't mind being the smartest man in the world. I just wish it wasn't this one.
Post Extras:
|