Introduction to the simplest and fastest way to implement Apache two-level domain names

Source: Internet
Author: User
Tags add implement lowercase domain domain name access root directory

First, you have a top-level domain name that has a universal domain name resolution, such as: domain.com

Second, open the mod_rewrite in the 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 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:

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.



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.