Implementation of domain name redirection system

Source: Internet
Author: User
The key technology of domain name redirection system is: implementing webpage redirection (Redirctory ). In essence, domain name redirection systems are completely different from virtual machine systems. There is a one-to-one correspondence between virtual domain names and IP addresses of virtual machines. The domain name to the system does not need to map the domain name and IP address one by one. That is to say, it does not need complicated domain name resolution mechanisms or virtual machines. the key technology of domain name redirection to the system is to achieve Redirctory on the web page ). In essence, domain name redirection systems are completely different from virtual machine systems. There is a one-to-one correspondence between virtual domain names and IP addresses of virtual machines. The domain name to the system does not need to map the domain name and IP address one by one. That is to say, it does not need complicated domain name resolution mechanisms or virtual machines. what it does is when you are requesting *. in yourdomain, redirect your browser to the actual address where your Html page is stored.

Next we will implement domain name redirection to the system step by step:

(Assume that your domain name is www.mydomain.com and the host address is 196.0.0.1 ).

First, set DNS to direct * .mydomain.com to our host address 196.0.0.1. (If you do not have your own DNS server, you can skip this step and contact your domain name service provider to ask them to help you direct * .mydomain.com to 196.0.0.1)

The DNS management tool of win2000 does not allow you to directly enter the host name as *, that is, we cannot directly Direct * .mydomain.com to the same IP address in win2000DNS management tool. However, we can change the winnt \ system32 \ dns \ mydomain. dns file. This file is saved in text format and can be opened on the WordPad.


We need to add A record * A 196.0.0.1 at the end.


We update server data files in WIN2000 DNS management tools. You will find that the mydomain.com domain contains the host "*" that we could not directly add. (Note: Your DNS settings will take effect in a few hours .)

To redirect this domain name to the system, we can select php + mysql to run the program on multiple platforms. Please check whether php and mysql are installed on your web server:

We use index.htm to read the HTTP header sent by the browser and send it to dns. php. the dns. php queries the database and returns the redirection address to the client.

Create mysql database mydomain

Create table dns (

Main char (60 ),

Link char (1, 255)

)

Main is used to save * .mydomain.com *

Link is used to save the redirection address corresponding to the domain name.

Create index.htm:

Script

This. location = "dns. php? Url = "+ this. location. href;

Script

Some may ask why php's GetAllHeader () function is not used to obtain the HTTP header information sent by the browser. Because the GetAllHeader () function only supports Apache web servers, we believe that most win2000 users use iis servers. Considering compatibility, we chose to use JavaScript to read the HTTP header information sent by the browser.



Create a dns. php file:


$ Domain = "mydomain.com"; // domain name

$ Database = "mydomain" // database

$ Datauser = "root"; // database user

$ Datapwd = ""; // database password

$ Dataserver = "localhost"; // address of the database server

?>


$ Db = mysql_pconnect ($ dataserver, $ datauser, $ datapwd );

?>




$ Url = str_replace ("http: //", "", $ url );

$ Url = strrev ($ url );

$ Url = strchr ($ url, strrev ($ domain ));

$ Url = strrev ($ url );

$ Main = str_replace (".". "$ domain", "", $ url );

?>




$ Str = "select link from dns where main = '$ main '";

$ Result = mysql_db_query ($ database, $ str, $ db );

List ($ link) = mysql_fetch_row ($ result );

?>





System error, or this domain name has not been registered!











The program is partially completed.

The last thing to do is to configure the web server. Here we take iis5.0 as an example.


Open the Internet information service management tool and create a new site * .mydomain.com (be sure to use this site as the default site of the independent IP address)


Use index.htm as the default document for * .mydomain.com.

Now the domain name is switched to the system. You can add a data entry to the database.

Insert into dns values ("etechnic", "www.etechnic.com.cn ")

In the future, as long as you enter etechnic.mydomain.com in the browser, you can enter the eNet technology channel.

Here we will only introduce the core content of domain name redirection. you only need to write a simple registration section to provide free domain name redirection service like my.yeah.net. Or you can e-mail zjzf_1@163.net to ask me for free all asp cgi php versions of the complete domain name turn to service programs.

The program is tested in iis5.0 + php4.0 + mysql and linux + mysql + Apache. I hope you can give me some advice on the shortcomings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.