通过Rewrite规则快速搭建大量的虚拟主机
| |
Posted in Linux/Apache on 2008/02/25 / 引用(0)
   项目需要为多个域名搭建网站。一般的做法是给apache添加一段virtualhosts。但是如果是大量的网站就麻烦了,通过学习apache rewrite模块发现有可以替代的快速方法。

1.需要创建一个vhost.map文件
内容如下

www.a.com E:\platform\a
www.b.com E:\platform\b
...


2.在apache的第一个虚拟主机(默认)virtualhost段里面加入rewrite 规则
内容如下:


RewriteEngine on

#字母小写方法
RewriteMap    lowercase    int:tolower

#引入 vhost.map文件
RewriteMap    vhost        txt:E:\platform\vhost.map

#确认拥有主机头报文
RewriteCond   %{HTTP_HOST}                 !^$

#将hostname变量转换成小写
RewriteCond   ${lowercase:%{HTTP_HOST}|NONE}  ^(.+)$

#转跳到host地址  
RewriteRule  ^/(.*)$ ${vhost:%1}/$1


保存,重起apache,完毕!每次需要增加一个网站,只要修改vhost.map文件,快速简单,域名配置的时候只要指向服务器的ip地址。

参考资料http://httpd.apache.org/docs/2.0/misc/rewriteguide.html   Mass Virtual Hosting

This entry comes from 本站原创 and has been read for 1791 times.It is tagged with , , .
1 Responses
suchasplus Email Homepage says:
at 2010/07/21 02:32
赞,那么vhost.map的管理有啥好办法么? 不至于更新一次就重新生成全部map吧...
分页: 1/1 第一页 1 最后页
发表评论

昵称

网址

电邮

OpenID登入 高级选项 表情