Article Title: the simplest and fastest way to implement Apache second-level domain names. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
First, you have a top-level domain name with wildcard domain name resolution, such as: domain.com
Next, enable mod_rewrite in httpd. conf.
Add the following content at the end of httpd. conf:
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
Here,/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: vhost. map in the directory of the path.
Content:
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 in the form of "Domain Name + space + absolute path.
Finally, under your website root directory/usr/local/www/data-dist, create the corresponding directory:
Domain, bbs, anyname, etc., theoretically unlimited.
In this way, when accessing www.domain.com through a browser, the files in the/usr/local/www/data-dist/domain directory are actually accessed. Similarly, accessing 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, and modify your second-level domain name and the actual path to. You do not need to restart apache.