How to resolve unlimited second-level domain names

Source: Internet
Author: User
Tags in domain web hosting hosting website

1. How to resolve unlimited second-level domain names

There are three ways to resolve unlimited second-level domain names:
No matter which type you use, you must use wildcard domain name resolution. Resolve * .test.com (Here we use test.com as an example) to your specified server.
For example:
* .Test.com 222.222.222.222

Note:
Before wildcard domain name resolution, you must confirm that the Domain Name Service Provider provides you with the wildcard domain name resolution service. Otherwise, the subsequent work will be futile.

Method 1: use Windows DNS resolution.
Steps:
1. Add test.com, as shown in figure
Post-related images:

2. Add a domain named * under test (right-click and add domain ).
Post-related images:

3. In the * domain, add a host (right-click, create a host, the host name is empty, and the IP address is the corresponding IP address for wildcard domain name resolution.
Post-related images:

The resolution is complete. test if Ping test.test.com is resolved to 222.222.222.222.

Method 2: Use a program to make judgments and adjustments.
Steps:
1. Leave the Host header of the IIS service blank and create default. ASP file, and set the execution priority of the new file to the highest (in the IIS setting attribute, set default. ASP to the top ).
Default. asp file code:
<%
Dim iurl
Iurl = Split (request. servervariables ("SERVER_NAME "),".")
If lcase (iurl (0) = "www" then
'Here is the home address of the website. Please select
Response. Redirect ("index. asp ")
Else
'If the second-level domain name is transferred to the address, please change the address here.
Response. Write ("<frameset> <frame src =" "**. asp? "& Iurl (0) &" .index.html ""> </frameset> ")
End if
%>

Method 3: Use isapi_rewrite URL Processing Engine
First, we will introduce isapi_rewrite:

Isapi_rewrite is a powerful URL Processing Engine Based on regular expressions. It is very similar to Apache's mod_rewrite, but it is designed for IIS.
Isapi_rewrite has two versions: isapi_rewrite full and isapi_rewrite lite.
Isapi_rewrite Lite is a free version, but does not support reverse proxy.
Isapi_rewrite full can only be downloaded to the 30-day trial version.
Second-level domain names can be resolved using an isapi_rewrite rule.
For example:
Map test.test.com to www.test.com/test/
The rules are as follows:
Rewritecond HOST :(?! Www \. | nhi) (. *) \. Test \. com
Rewriterule/(. *)/$1/$2 [I, L]


Comparison of the three methods:
I personally think that, method 1, the resolution speed will be faster, but it has not been verified. I just feel that the system comes with something better.
In addition, in method 1 and 3, one server can perform multiple wildcard domain name resolution, while in method 2, one server can only perform wildcard resolution for one domain name.

Due to my limited personal ability, I wrote this article by referring to the relevant materials. If you have any mistakes, please let us know. Thank you.


 

 

First, add your domain name to the IP address, and then add an empty Host Header in IIS.

When accessing site1.yourdomain.com using the following regular expressions,

Actually requested yourdomain.com/domain.asp? Name = Site1

Rewritecond HOST :(?! Www.) ([^.] +) .yourdomain.com
Rewriterule (. *)/domain. asp? Ame = $1 [I]

========================================================== ======

In httpd. conf, perform the following operations on a host:

<Virtualhost IP: 80>
Rewriteengine on
Rewritecond % {http_host} [^.] + \. Domain Name \. com $
Rewriterule ^ (. +) % {http_host} $1 [c]
Rewriterule ([^.] +) \. Domain Name \. com (. *)/$1 $2
Other configuration files
</Virtualhost>

Then, you can set up a wildcard DNS resolution to the corresponding IP address.
You can implement the following solution.


Domain Name: domain.com
Absolute path:/home/domain.com/
Automatically resolve www.domain.com to/home/domain.com/www/
Abc.domain.com is automatically parsed to/home/domain.com/abc/
And so on.

Directly create a folder for the sub-domain name. You do not need to restart Apache.

Wildcard domain name resolution is to resolve all the customer's domain names to the same IP address.
For example, the customer's domain name a.com, * .a.com under all resolved to the same IP address.
For example, if B .a.com is set, it will automatically resolve it to the same IP address as a.com.

Wildcard domain names refer to * in a 123.123.123.123 or * In cname www.aaa.com

Usage of wildcard domain name resolution:

1. The domain name can support unlimited subdomain names (this is also the biggest use of wildcard domain name resolution ).
2. Prevent Website access problems caused by incorrect user input.

There are two ways to set wildcard domain name resolution in the DNS server

1. Set * .a.com's a record or cname record to point to an IP address/server name in domain name resolution (this method is not supported by VM Users)
2. set * .a.com to forward to the http://www.a.com in domain name Forwarding (the VM can support this forwarding method, the user can judge the domain name visitors want to access in their own program ), we will explain it in the program technical documentation.

Example 2:
Http://www.xuega.com/klein/blog/article_321.html

The key to implementing dynamic second-level domain name resolution is how to put forward the unique name, because the matching in rewriterule does not include domain name matching. In fact, this is a layer of window paper, put the domain name in the "path" first, and then rewrite the "path" once, that is, add a step of transition. In this case, it is still difficult to give an instance.

First, write one according to the requirement of the article I wrote last time, assuming dynamic resolution * .iecn.cn.

Note that a so-called Fan Domain name resolution should be done first, that is, to resolve all * .iecn.cn to an IP address. This is not the scope of this article.

Related configuration in Apache is as follows:

<Virtualhost _ default _: 80>
Serveradmin yourmail@domain.com
DocumentRoot/yourwwwroot/. Default
Servername all-sites
Errorlog logs/all-sites-error_log
Customlog logs/all-sites-access_log common
# The following three lines implement dynamic resolution
Rewritecond % {http_host} ^ [a-z0-9 \-] + \. IECN \. cn $
Rewriterule ^/(. *) $/% {SERVER_NAME}/$1 # Note ##
Rewriterule ^/([a-z0-9 \-] +) \. IECN \. CN/(. *) $/yourwwwroot/$1/$2 [l]
# If it is not parsed, throw it to your own PHP for processing.
Rewriterule ^. * $/index. php [l]
</Virtualhost>

Note that the place I marked is a transition. Let's talk about the process. Assume that you are visiting:
Http://zhong.iecn.cn/xxx
The first step is to rewrite it to/zhong.iecn.cn/xxx.
The second step of rewriting is/yourwwwroot/Zhong/xxx. Other operations are similar to what we mentioned before.

Another example that may be more common is to assume that a blog system requires
Http://xxx.iecn.cn
Implicitly rewrite
Http://blog.iecn.cn/blog.php? U = xxx
Here xxx can be regarded as a user name. We must have seen many such requirements, but I have explained them more.

I agree to do Fan Domain name resolution first. Rewrite Apache as follows (only the rewrite part is written ):

Rewritecond % {http_host} ^ [a-z0-9 \-] + \. IECN \. cn $
Rewriterule ^ /? $/% {Http_host}
Rewriterule ^/[a-z0-9 \-] +) \. IECN \. CN /? $/Blog. php? U = $1 [l]

ZZ from http://blog.iecn.net/blog.php? Do = showone & tid = 1013


Dynamic resolution of arbitrary domain names using rewrite in Apache

The mod_rewrite module of Apache is very powerful. I will write more instances later.

I don't want to talk about the use of mod_rewrite. I provide the addresses of two related documents:
Http://w.yi.org/ftp/FAPM/apache/Apache2/zh/mod/mod_rewrite.html
Http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/mod/mod_rewrite.html

If you just want to use a ready-made copy, you can change it directly. If you want to understand the technology, you must first master the two technologies:
Use mod_rewrite in Apache (refer to the two addresses provided above)
Regular Expressions (this is a technology that is very useful in many places)

Let's talk about the actual configuration of the IECN. NET Server.

I am used to using namevirtualhost. If your server only wants to use this dynamic resolution, the configuration file will be the same. If you want to keep the configuration of some special sites, use namevirtualhost.

In Apache, if namevirtualhost is enabled, it will be in the first group of virtualhost by default if no matching resolution is found, therefore, our dynamic Parsing is naturally placed in the first group of virtualhost (some Apache configurations are not mentioned here. Please refer to the relevant documents .), As follows:
<Virtualhost _ default _: 80>
Serveradmin yourmail@domain.com
DocumentRoot/yourwwwroot/. Default
Servername all-sites
Errorlog logs/all-sites-error_log
Customlog logs/all-sites-access_log common
# The following two lines implement dynamic resolution
Rewritecond/yourwwwroot/% {SERVER_NAME}-d
Rewriterule ^/(. *) $/yourwwwroot/% {SERVER_NAME}/$1 [l]
# If it is not parsed, throw it to your own PHP for processing.
Rewriterule ^. * $/index. php [l]
</Virtualhost>

Replace yourwwwroot with your own path. Note that servername does not make it take effect. refer to the following two lines:
Rewritecond/yourwwwroot/% {SERVER_NAME}-d
Rewriterule ^/(. *) $/yourwwwroot/% {SERVER_NAME}/$1 [l]

The first line is a rewrite condition. The condition here is: if the path/yourwwwroot/% {SERVER_NAME} exists, % {SERVER_NAME} is the domain name of your site, -D indicates that this path exists (if it is a file, it is-F );
The second row is a rewrite rule. The premise for executing this rule is that it matches the regular expression of the rule and meets the rewrite condition before it (that is, the first row just mentioned. The matching is. *, that is, all, that is, as long as the condition of the first row is true, it will be overwritten to/yourwwwroot/% {SERVER_NAME}/$1, % {SERVER_NAME} is the domain name of the site, and $1 is matched. *.

OK. Now it is clear. Suppose www.domain.com points to this server, and when you access it (Here we assume that this domain name is not resolved in other virtualhost ), let's see how it works:
First, it comes to the default virtualhost group when no matching Parsing is found;
Determine whether/yourwwwroot/www.domain.com exists;
If yes, redirect to/yourwwwroot/www.domain.com.

If you access http://www.domain.com/test.html, the system will redirect to/yourwwwroot/www.domain.com/test.html.

That is to say, if you create a directory with the same name as the domain name under yourwwwroot (with Apache access permissions), you can resolve the domain name.

It seems a bit difficult to say, but it is actually very simple.

This is a dynamic resolution of any domain name. If you have time, write a second-level domain name resolution for the same domain name. In fact, you can simply change this.

 

 

 

The rewrite module is powerful and can easily extract Host header information.

0. First, a valid top-level domain name is required, and the second-level domain name under this domain name is set to Pan resolution to the IP address of the server where the VM is located (for example, * .77ya.com => 123.234.55.101 ).

1. Download The isapi_rewrite lite free version at http://www.helicontech.com/download.htm. The version does not need to be too high. If you want to pay $, it would be nice to use the full version. Installation.

Note: The lite version does not support virtual host-level configuration, but only the configuration (that is, the DLL can only read the global configuration httpd. ini in its own installation directory ). If it is used only for any second-level domain name resolution of a virtual host, you can place isapi_rewrite.dll only in the configuration of the virtual host (that is, it is not inserted in IIS's "website> ISAPI filter, is added to the ISAPI filter of the web hosting website.

2. Leave the Host header of the virtual host that requires the second-level domain name blank so that all the virtual host domain names not separately configured on the server are directed here. Note! Instead of creating a website with no master node on the server, you must configure the rewrite of the URL on the current website with the second-level domain name to be implemented. This is important.

3. When isapi_rewrite is installed, it is automatically configured to cancel global settings in IIS (IIS> website> ISAPI filter, delete isapi_rewrite). On the virtual host (website) that requires second-level domain name resolution) configure isapi_rewrite.dll (attribute> ISAPI filter> Add ..., the name can be written as needed, such as URL-Rewrite ).

4. modify the configuration file httpd. ini in the isapi_rewrite installation directory. Example:
Java code
[Isapi_rewrite]
Repeatlimit 1
# Defend your computer from some worm attacks
Rewriterule .*(? : Global. Asa | Default \. Ida | Root \. exe | \. \.). *. [F, I, O]

# Exclude the domain name that the current VM needs to access (web.77ya.com www.77ya.com)
# Rewritecond HOST :(? : Web | www) \. 77ya \. com

# In most cases, it is a system that currently provides second-level domain name services (such as a website creation system)
Rewritecond HOST: WEB \. 77ya \. com

Rewriterule (. *) $1 [l]

# Solve the problem of nonstandard directories (no at the end)
# But the premise is that the directory name does not include '.' And the file name must contain; otherwise, the two cannot be distinguished.
# This rule is not required if the directory name in the URL is specified
Rewriterule ^/([^.] [^/] $)/$1/[L, R]

# Extract any second-level domain name (that is, the first word)
# Use [a-zA-Z0-9 _-] to limit the name character, rewrite the URL to the home/subdirectory
# For example, test.77ya.com => web.77ya.com/home/test
Rewritecond HOST: ([a-zA-Z0-9 _-]) \. 77ya \. com
Rewriterule ^/(. *)/home/$1/$2 [I, L]


Note! The above rules cannot be written
Rewriterule ^/(. *) HTTP \: // web \. 77ya \. com/home/$1/$2 [I, L]

This is also the reason why the system must be resolved on its website. If [I, R] is used at the end, the access is acceptable, but the actual URL is displayed in the address bar of the browser, which cannot achieve the effect of transparent second-level domain names.

Summary:

I checked Google before and did not find a simple implementation example. In fact, this is mainly a rule issue. Even if isapi_rewrite is placed in the global configuration of IIS's "website", it is acceptable because the rule does not match other websites (top-level domain name restrictions ), rewrite does not work. But in the global configuration, access to other websites also needs to go through this. dll filter, more or less unreasonable.

After successful configuration and running, the full version must be used online (version 1.x is feasible ). Therefore, we will post the usage of the lite free version here.

(Note: At last, you may need to restart the IIS server and check whether rewrite in the ISAPI filter has been loaded-green up arrow. In addition, if it is an NTFS file system, the isapi_rewrite installation directory requires the write permission of the Website user or everyone !)

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.