[bdNOG] Redirect Domain to Web Server

Brian Candler brian at nsrc.org
Thu Sep 25 01:06:13 BDT 2014


On 24/09/2014 07:00, nog-request at bdnog.org wrote:
>
> I want to redirect my domain to web server using my DNS server (bind9).
>
> Example :  If anyone request for banglaphone.net.bd in a browser that 
> will be redirected to www.banglaphone.net.bd by DNS server (bind9)
>
A "redirect" is not done using DNS, but using HTTP.

- client resolves banglaphone.net.bd to an A record
- client connects to web server at that address, and asks for 
virtualhost banglaphone.net.bd
- web server responds with a redirect response (e.g. code 302 and a 
Location: header) pointing to www.banglaphone.net.bd
- client now starts a fresh request: it looks up www.banglaphone.net.bd 
in the DNS etc.

So to make this work, you have to:
1. In DNS point banglaphone.net.bd to some webserver that you control 
(which could be the same one as www.banglaphone.net.bd, but doesn't have 
to be)
2. Create a virtual host "banglaphone.net.bd" on that server
3. Configure it to return a redirect to www.banglaphone.net.bd.

If the webserver is Apache you can do this using the Redirect feature:
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect

HTH,

Brian.

P.S. right now in the DNS, banglaphone.net.bd points to 180.210.129.3 
[which is blocking port 80 entirely], and www.banglaphone.net.bd points 
to 180.210.130.16

I can see you don't currently have a virtual host for banglaphone.net.bd 
on the latter server yet. You can test this using telnet. Note that you 
have to hit Enter a second time after the Host: header line.

$ telnet www.banglaphone.net.bd 80
Trying 180.210.130.16...
Connected to www.banglaphone.net.bd.
Escape character is '^]'.
GET / HTTP/1.0
Host: banglaphone.net.bd

HTTP/1.1 200 OK
Date: Wed, 24 Sep 2014 19:03:34 GMT
Server: Apache/2.2.22 (Ubuntu)
Last-Modified: Wed, 10 Jul 2013 11:51:13 GMT
ETag: "1180cfb-116-4e126e4f89261"
Accept-Ranges: bytes
Content-Length: 278
Vary: Accept-Encoding
Connection: close
Content-Type: text/html

<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, 
yet.</p>

Your Are Visiting From:
<?
echo $_SERVER["REMOTE_ADDR"];
echo $HTTP_SERVER_VARS["REMOTE_ADDR"];
?>

</body></html>

So right now, if you swing banglaphone.net.bd to point to 
180.210.130.16, users will see the "It works!" page. But you can create 
the redirect configuration in advance of this, and test it using the 
telnet method above.

Alternatively, you can create an entry in your HOSTS file on the client 
machine you're testing from:

180.210.130.16    banglaphone.net.bd

and point your browser to banglaphone.net.bd to test. When it's working, 
swing the DNS and remove the HOSTS entry.



More information about the nog mailing list