Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We are using Bind9 on our DNS servers. We have all of our zone files structured with the following format in our /var/named/slaves directory:

mywebsite.com.hosts
mysecondwebsite.com.hosts 

Each .hosts file contains the following information:

$ORIGIN . 
$TTL 3600       ; 1 hour
mywebsite.com             IN SOA  dns1.xxx.xxx. postmaster.xxx.xxx. (
                                2012042601 ; serial
                                3600       ; refresh (1 hour)
                                600        ; retry (10 minutes)
                                86400      ; expire (1 day)
                                3600       ; minimum (1 hour)
                                )
                        NS      dns1.xxx.xxx.
                        NS      dns2.xxx.xxx.
                        A       168.xxx.xxx.xxx
$ORIGIN mywebsite.com.
www                     A       168.xxx.xxx.xxx 

Our named.conf file has the following info:

options {
        directory "/etc";
        pid-file "/var/run/named/named.pid";
        recursion no;
        notify yes;
        listen-on { 10.xx.xx.xx; 127.0.0.1; };
        allow-transfer { 10.xx.xx.xx; };
        version "[bitch-got-denied]";
        };

zone "." { type hint; file "/etc/db.cache"; };

zone "mywebsite.com" { type master; file "/var/named/slaves/mywebsite.com.hosts"; allow-update { none; }; }; zone "mysecondwebsite.com" { type master; file "/var/named/slaves/mysecondwebsite.com.hosts"; allow-update { none; };

Lets say I have both Mywebsite.com & Mysecondwebsite.com .hosts files pointing to the same IP. If someone goes to Mywebsite.com or Mysecondwebsite.com it resolves to the same server, the only obvious difference is the name in the URL bar (depending on which FQDN the client uses to navigate to our domain.)

My question and what I need help with is, I want when someone goes to Mysecondwebsite.com that in the URL bar it gets redirected to Mywebsite.com. I know I can use my hosting company to just do a redirect (standard or stealth) through their online interface, but wanted to see if this could be done on our DNS servers. I simply want a standard redirect. Perhaps I need to mess with the Webserver itself... Any feedback on the best way to accomplish this would be greatly appreciated!

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

No - an HTTP redirect (the kind that changes the address bar) can never be done in DNS alone; DNS providers who offer this kind of service simply point the name to their own HTTP server and configure the redirect there.

You will need to configure this on your web server - let us know what kind of server it is and we can help you through configuring the redirect.


Edit: To configure your Apache to redirect:

  • Add a new site file: /etc/apache2/sites-available/redirect
  • Give that file these contents:

    <VirtualHost *:80>
        ServerName mysecondwebsite.com
        Redirect permanent / http://mywebsite.com/
    </VirtualHost>
    
  • Enable the site: a2ensite redirect

  • Activate the new config by gracefully restarting the Apache service: service apache2 reload
share|improve this answer
    
Thanks for the info Shane! Server version: Apache/2.2.20 (Ubuntu) –  Blake Jun 14 '12 at 17:17
    
@Blake Ok! Is the configuration mostly standard, with configuration for your main site in /etc/apache2/sites-available/default? –  Shane Madden Jun 14 '12 at 17:28
    
Yes. The configuration is standard. –  Blake Jun 14 '12 at 18:14
    
@Blake I've edited my answer with a basic redirection config. Let me know if that doesn't work for you. –  Shane Madden Jun 14 '12 at 18:27
    
This is exactly what I needed. Everything works flawlessly, thank you for the guidance Shane! I really appreciate your time –  Blake Jun 14 '12 at 18:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.