Apache下添加二级域名的方法

httpd.conf 中需要打开mod_rewrite功能,即修改/etc/httpd/conf/httpd.conf文件,在最下方添加如下代码:

RewriteEngine on 
RewriteMap lowercase int:tolower 
RewriteMap vhost txt:/etc/httpd/conf/vhost.map 
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$ 
RewriteCond ${vhost:%1} ^(/.*)$ 
RewriteRule ^/(.*)$ %1/$1

其中/etc/httpd/conf/为Apache的配置文件目录。然后在其下创建vhost.map文件,并写入类似如下内容:

domain1.com /srv/http
www.domain1.com /srv/http
blog.domain1.com /srv/http/blog

以后,输入www.domain1.com或者domain1.com,就会转向/srv/http目录下文件;输入blog.domain1.com则会转向/srv/http/blog目录下的文件,从而实现二级域名。

本文为悠然居(https://wordpress.youran.me/)的原创文章,转载请注明出处!

Leave a Reply

Your email address will not be published. Required fields are marked *