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