Search | View Active Threads | View New Posts
Current Time: 05:37 AM


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Wales (UK)

    Linux server setup for domain traffic redirects - inc wildcard dns and 404's

    Linux server setups for traffic redirection - apache/php/bind

    An easy to manage server setup for traffic from numerous domains is different than most web hosts are used to as they are used to completely different sites for each domain/client.

    This thread explains a simple setup that allows new domains to easily be redirected to ppc park pages - with the server acting as both nameserver and webserver. It is not meant to be a line-by-line setup, but goes into more detail than a basic overview would - it should be enough to give an insight into how these things hang together

    It is supplied "as is" with no warranty - explicit or implied - for suitability, completeness or errors.

    introduction to how the dns system works (ignoring isp caches etc):

    When someone types a domain into their address bar their system checks the registry to get the location of nameservers that have the authority for the domain. these nameservers are what actually hold the ip address (location) that the domain should resolve to. so when you register a domain and assign it nameservers, those nameservers are the ones that will then need to hold the correct IP address details for that domain name. Once the browser has the ip address from the nameserver it can then send its request to the webserver at that ip address. the webserver looks at the domain name in the request and issues the relevant data which will usually be a html webpage for a type-in.

    So in summary:
    • Address typed into browser
    • Authoritative nameservers for that domain obtained from registry
    • Those nameservers queried with the domain name to get an ip address
    • The webserver at that ip address is sent the page request
    • The webserver then issues content relative to that domain name
    The use of the word "server" can get confusing, this might help to clarify it:

    A server is a piece of hardware with an operating system on it that listens to network traffic

    A nameserver is a program that runs on a server and issues the IP addresses of where a domain should resolve to in response to being given a domain name.

    A webserver is a program that runs on a server and issues content based on the domain name. Traffic gets to the webserver by being directed by a nameserver

    A server can run a webserver and nameserver(s) on the same piece of hardware and can have more than one IP address that routes to it.


    Basic setup

    Nameserver - Initial setup:

    For the sake of this exercise, lets assume the server host setup the server to resolve on ip address: 111.222.333.1 and they configured it so that ns1.domain.tld resolves to that ip address and that the secondary nameserver was also configured to be run from the one server as ns2.domain.tld on address 111.222.333.2. Note: whilst its possible to run 2 nameservers (primary and secondary) on one server, if the server fails they both fail - this isn't an issue if you only run the webserver on this server as if the nameservers have failed its likely the webserver has failed too.

    For the nameserver to issue IP addresses when queried for domains it needs to know which domains it should handle and what it should return when queried. There are 2 main file types used for this:

    1) zone db files - usually located in /var/named - these contain the specific configuration that is returned when queried.
    For traditional hosting, each domain/client on the server might have its own zone db file - but for traffic its easier to just set up one file. this is what a zone db file might look like for traffic conversion:

    $TTL    900
    @               IN      SOA     ns1.domain.tld. root.ns1.domain.tld. (
                                    2005030501 ;serial number YYYYMMDDxx
                                    10800 ;refresh time in seconds
                                    3600 ;retry time in seconds
                                    604800 ;time in seconds
                                    900 ) ;minimum time to live in seconds
                    IN      NS      ns1.domain.tld.
                    IN      NS      ns2.domain.tld.
    ;host information
                    IN      MX      5 mail.domain.tld.
                    IN      A       111.222.333.1
    *               IN      A       111.222.333.1
    breaking it down for the important stuff:

    TTL is the "time to live", when a nameserver is queried for a domain the TTL tells the recipient how long they should consider the reply as "current" in their cache (a cache a memory, which is used to save them looking it up every time) - the reason for this shorter ttl is that if a change of ip is needed for some reason, the change is picked up quickly (15 minutes in this case if their cache adheres to the ttl).

    the serial number has to be incremented each time a change to the zone db file is made, this way a running nameserver knows if it has changed since the last time it loaded it in.

    the IN A records tell the querying browser which IP address to send their request for content to. the blank line is to handle domain.tld and issues 111.222.333.1 in response, the "*" is a wildcard and this allows anything.domain.tld to be resolved to 111.222.333.1 too. So if a user mistyped www.domain.tld as ww.domain.tld it will still resolve - likewise if they typed in wibble.domain.tld that would resolve too. a lot of zone db's are set up with explicit subdomains so instead of "*" the host might set it up with just blank and "www" - that is why a lot of sites don't resolve if ww.domain.tld is typed in and people may assume the site is down not realizing they made a typo of "www".

    So lets take it that we have the above zone db file saved as /var/named/

    2) /etc/named.conf is the file that contains which domain names the nameserver will have authority for.

    to add domains to the server, all that needs to be done is to add an entry like this for each domain to /etc/named.conf:

    zone "somedomain.tld" {
    type master;
    file "";
    and then to reload the nameserver (that tells the nameserver to pick use the additional changes) - this can usually be done with:

    /etc/rc.d/init.d/named reload

    [ If you want to make it easier each time, you can create a file with that as content called something like /usr/bin/nameload and then chmod +x /usr/bin/nameload - this way just typing the easier shortcut "nameload" will reload the nameserver]


    Apache listens to requests sent to its IP address. It looks at the domain name and checks its configuration file to find where the files it should return are stored. The configuration file is called httpd.conf - the location of this file will depend on how the server was setup (you can find it by typing in "locate httpd.conf").

    Normally, the httpd.conf file would be set up for every domain the server manages as normally each domain on a server would issue different content. But for traffic, there will be just one main location to use - we can use the file at that location to determine what to do based on the domain name being looked up. This makes management much easier.

    Apache can be setup to handle "virtualhosts" - that means it issues different data for different domains. As mentioned above, these would normally be explicitly configured - but apache has a useful feature in that for domains not explicitly setup it will use the first one. this means that not every domain has to be set up.

    To set up the defaul virtualhost requires adding something like this to the end of httpd.conf file (assuming it has no other virtualhost settings in there).

    NameVirtualHost 111.222.333.1
    <VirtualHost domain.tld>
    ServerName domain.tld
    ServerAdmin webmaster@domain.tld
    DocumentRoot /www/htdocs/redirect
    ServerAlias *.domain.tld
    DirectoryIndex index.php
    ErrorDocument 404 /index.php
    The above includes the ErrorDocument 404 line which handles pages that no longer exist or are mistyped and redirects them to the "home" page (these are known as 404 errors)- which is set to be found at /www/htdocs/redirect/index.php in the above example (a combination of the root and the directoryindex value which is the file to be used if no file is given ie domain.tld vs domain.tld/page.ext).

    once added the webserver needs to be restarted to take effect, this can be done using apachectl (which can again be found using "locate apachectl") type in "/path/apachectl restart" where path is the path to apachectl.

    All that remains is to set up the actual file that handles it all. this is the file at /www/htdocs/redirect/index.php using the above example.

    referer redirects

    the easiest type of redirect is if the ppc company can determine the domain name from the referer, as this means you don't have to work out what the domain was yourself - the ppc company does by looking at what the domain was that sent the person to them.

    for this type of redirect, the content for index.php can simply be the following to retain the domain in the address bar:

    <title>Find It Here</title>
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    <frameset rows='*' frameborder='NO' border='0' framespacing='0' cols='*'>
    <frame name='content' src='http://ppc_companies_referer_detect_url></frameset>
    <a href='http://ppc_companies_referer_detect_url'><font size='+2'>
    Click Here To Continue
    or, if you aren't bothered about the address in the address bar a header redirect, index.php can be just:

    header("location: http://ppc_companies_referer_detect_url");
    this tells the browser to go to that url and displays the new url in the address bar.
    Last edited by safesys; 2005-03-13 at 11:01 PM.

  2. #2
    Join Date
    Sep 2002
    Wales (UK)
    domain based redirects

    If you want to know the domain name at the server side, so you log traffic, make different actions based on the domain or where you have to send the domain to the ppc company the code gets more complex.

    This is a complex example of an index.php file that can be used to do different things based on the domain. Its longer than it needs to be to try and make the steps clearer:

    // *** This code gets the domain name typed and gives several variables that can be used
    // *** to determine where the user is sent.
    // *** $domain = the full name with tld eg keyword.tld
    // *** $keyword = the keyword of the domain eg keyword
    // *** $tld = the tld without period eg uk or com
    // *** this part handles domains 
    if($tld=="uk") {
    // *** this part handles non domains
    else {
    // *** this is the default url traffic is sent to if not overriden
    // *** here you can hardcode specific domains
    if($domain=="domain1.tld") {$gotourl="$domain"};
    if($domain=="domain2.tld") {$gotourl="$domain"};
    // *** this redirects to a different url without stealth/frames so 
    // *** the new address appears in the address bar
    // *** it then exits which stops it executing any further code
    if($domain=="domain3.tld") {
    header("location: http://www.anothersite.tld");
    // *** stealth/frame redirection - includes click link for browsers that don't do frames
    print "<html><head>";
    print "<title>$domain for $keyword</title>";
    print "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
    print "</head>";
    print "<frameset rows='*' frameborder='NO' border='0' framespacing='0' cols='*'>";
    print "<frame name='content' src='$gotourl>";
    print "</frameset><noframes>";
    print "<a href='$gotourl'><font size='+2'>Click Here To Continue</font></a>";
    print "</noframes>";
    print "</html>";
    // *** End
    The above can be built on to use databases insted of hard-coded "if's" - but thats beyond the scope of this introduction.
    Last edited by safesys; 2005-03-13 at 11:15 PM.
    When using google for counts - use double quotes for usage counts for multiword terms and set "match type" to "exact" for all search volume lookups. Click here for more info

  3. #3
    Join Date
    Sep 2002
    Wales (UK)
    Once the setup is done for the nameserver and webserver, to add new domains (using the default redirect at index.php) - it is simply a case of adding a new entry to /etc/named.conf of the form:

    zone "somedomain.tld" {
    type master;
    file "";
    and then reloading the nameserver with something like:

    /etc/rc.d/init.d/named reload

    or "nameload" if you set that up as a shortcut above
    When using google for counts - use double quotes for usage counts for multiword terms and set "match type" to "exact" for all search volume lookups. Click here for more info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Domain Escrow Services Domain Registrar, Marketplace and Revenue Optimizer
Trellian Direct Search Network

Industry Events

11-14 August 2019
Affiliate Summit East
New York, NY

4-6 March 2019
Las Vegas

15-18 September 2018
MERGE 2018
Orlando, FL


How do you invest in domains?
to see the Poll results!
Domain Tools | Domain Directory | Registrar Stats | Domain Glossary | Industry Events | FAQ | Members | Terms | RSS | Link To Us | Advertise | Contact Us
Other Related Trellian Services: Registrar  | Marketplace  | Domain Manager  |  Free Search Toolbar  |  Free Webpage Builder  |  Keyword Research
Direct Search Navigation  |  Search Engine Submission and SEO Tools
Copyright © 2002 a Trellian Company 2014 Bronze Sponsor - Internet Commerce Association