The perfect implementation of level two domain name

Source: Internet
Author: User

1, what is a two-level domain name , I am afraid everyone is very clear, for example, such as www.fenlei123.cn generally as a domain name, or the primary domain name, then http://beijing.fenlei123.cn and/HTTP Shanghai.fenlei123.cn is the level two domain name.

The advantages of a two-level domain name
In fact, for the search engine, the general is the different two-level domain name as a different site to view, that is, to a large extent can be two-level domain name as a separate site to treat. Therefore, in the search engine ranking weight, for the two-level domain name to give a very high weight. More importantly, most of the search engines, especially Baidu, basically will be unconditionally included in the two-level domain name. In other words, your two-level domain name, although the lack of outside the chain, he can also be included for you, and for the ordinary Web pages, included is not so happy.

The analytic method of level two domain name
Basically all DNS support the pan domain name resolution, so we just have to resolve the pan domain name to an IP on it. However, there is a problem, that is, in general, a server only allow an empty host header, if your server already has other domain names occupy the empty host header, you need to write in the host head of your site all possible two-level domain names. Therefore, we recommend using a standalone server to implement a pan two domain name.

Two-level domain name ASP.
For the website program, the implementation of level two domain name is basically implemented by redirection, for the system using ASP, we use the following method (ASP and other languages are very similar):
In the Global.asax file, intercept the Application_BeginRequest event, rewritten as follows:
string url = Request.Url.AbsoluteUri;
String strmatchdomain = @ "[url=http://(w{3}\.)?" ([^\.] *)[\.] *fenlei123\.cn]http://(w{3}\.)? ([^\.] *)[\.] *fenlei123\.cn[/url] ";
String newurl = "";
String strdomain = Split2info (URL, strmatchdomain);
if (strdomain! = NULL && Strdomain! = "")
{
if (URL. ToLower (). EndsWith (@ "default.aspx"))
{
if (strdomain! = "All")
{
Newurl = string. Format ("[Url=file://\\partersite.aspx?code={0]\\partersite.aspx?code={0[/url]}", strdomain);
This. Context.rewritepath (Newurl);
}
}

Explain this code to everyone:
If we ask for such an address: http://qingdao.fenlei123.cn, after the Split2info () method uses the regular expression processing, Will get the Qingdao in front of fenlei123.cn, that is, we use regular expressions to get the name of a city. Then we determine if this URL is Default.aspx end, because all two-level domain names are default.aspx end (for this site), and then the URL redirection that is, this is the final page that is actually going to be executed.
In this way, we implement a pan-level two domain name through pan-parsing and Web page re-image, of course, can also be implemented in other ways, such as the IIS-level DLL redirection.

2, two level domain name perfect realization and Example

First, you have a top-level domain name that has a pan-name resolution, for example: domain.com
Second, open the mod_rewrite in httpd.conf

After that, at the end of httpd.conf, add the following:

Rewriteengine on
Rewritemap lowercase Int:tolower
Rewritemap Vhost Txt:/usr/local/etc/apache/vhost.map
Rewritecond ${lowercase:%{server_name}} ^ (. +) $
Rewritecond ${vhost:%1} ^ (/.*) $
Rewriterule ^/(. *) $%1/$1

The/usr/local/etc/apache is the path of your Apache server configuration file, which is changed according to the actual situation.
Then, create a file in the directory where the path is located: vhost.map
The contents are:

Www.domain.com/usr/local/www/data-dist/domain
Bbs.domain.com/usr/local/www/data-dist/bbs
Anyname.domain.com/usr/local/www/data-dist/anyname

The above sections are: "Domain + space + absolute path" form.

Finally, under your website root directory/usr/local/www/data-dist, create the corresponding directory:
Domain, BBS, anyname and so on, theoretically can be unlimited.

This way, when you access www.domain.com through a browser, you are actually accessing the files in the/usr/local/www/data-dist/domain directory. Similarly, access to bbs.domain.com actually accesses files in the/usr/local/www/data-dist/bbs directory. And, you can
Change Vhost.map at any time to add, delete, modify your level two domain name and the actual path you are pointing to, without restarting Apache.

The perfect implementation of level two domain name

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.