The implementation method of Apache two-level domain name resolution _linux

Source: Internet
Author: User
Tags lowercase php script
Copy Code code as follows:

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 to your Apache server configuration file, which is changed according to the actual situation.
Then, create a file in the directory that contains the path: Vhost.map
Content is:
Copy Code code as follows:

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 parts are: "Domain name + space + absolute path" form.

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

In this way, through the browser, access to www.domain.com, the actual access is the/usr/local/www/data-dist/domain directory of files. Similarly, the access bbs.domain.com actually accesses the files in the/usr/local/www/data-dist/bbs directory. And, you can
Change Vhost.map at any time to add, remove, and modify your level two domain name and the actual path you point to, without restarting Apache.

The first step: Open the Apache configuration file httpd.conf, remove the LoadModule rewrite_module modules/mod_rewrite.so front of the # number.
Step two: The end of the configuration file plus
Rewriteengine on
Rewritemap lowercase Int:tolower
#定义映像文件
Rewritemap Vhost Txt:/apache/vhost/vhost.map
#处理变名
Rewritecond%{request_uri}!^/icons/
Rewritecond%{request_uri}!^/cgi-bin/
Rewritecond ${lowercase:%{server_name}} ^ (. +) $
Here to do file-based remapping
Rewritecond ${vhost:%1} ^ (/.*) $
Rewriterule ^/(. *) $%1/$1
Rewritecond%{request_uri} ^/cgi-bin/
Rewritecond ${lowercase:%{server_name}} ^ (. +) $
Rewritecond ${vhost:%1} ^ (/.*) $
Rewriterule ^/(. *) $%1/cgi-bin/$1

Note: The Vhost.map file is a domain name and space image file, in the following format:
Http://www.abc.com/vhostusr/www.abc.com
Http://www.xyz.com/vhostuser/www.xyz.com
Http://www.cccbbbbs.net/vhostuser/www.ccbbbb.net
Step Three: Save the configuration file and restart Apache. When opening the space of the binding domain name, just add the corresponding record in the Vhost.map file and set up the corresponding folder OK ~ ~ ~
In fact, this can be done with PHP script, very simple ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Note AH: php_admin_value open_basedir "path, this option to match good AH ~ ~ Novice If not understand, do not move this ~
==============================================
Method Two,

Copy Code code as follows:

Rewriteengine on
Rewritecond%{http_host} [^.] +\. Domain \.com$
Rewriterule ^ (. +)%{http_host}$1 [C]
Rewriterule ([^.] +) \. Domain name \.com (. *)/$1$2

Other configuration files

Then, in DNS, open a pan resolution to the corresponding IP address.
You can implement the following scenario.

Domain Name: domain.com
Absolute path:/home/domain.com/
www.domain.com Automatic parsing to/home/domain.com/www/
Abc.domain.com Automatic parsing to/home/domain.com/abc/
And so on, subdomains can be automatically resolved to the folder where the/home/domains.com/corresponds to the name of the child name
A folder that directly establishes the name of a subdomain can be used. You do not need to restart Apache. /vhostuser/www.ccbbbb.net/vhostuser/www.xyz.com/vhostusr/www.abc.com

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.