Apache的Rewrite心得

[不指定 2006/12/20 18:43 | by ipaddr ]
Apache的Rewrite心得

最近公司要转移服务器,服务器上有几十个站点正在运行,希望转移的期间,服务不受影响,所以用Apache的mod_rewrite做了些处理.
大致环境是这样的,服务器有site[1-50].TA.com域名和site[1-50].TB.com域名,在开始转移服务器之前,先将site[1-50].TB.com指向新的服务器IP,同时,在新的IP上,运行Apache,将siteX.TB.com的访问Rewrite回TA.com,经过一天后,再将TB.com解析到新IP,同时,转移数据库和WEB服务到新IP,并将原来的服务器上的Apache Rewrite到SiteX.TB.com,访止部分用户缓存了DNS,导致仍然访问原服务器。

Rewrite写法大致如下:

[code]#加载mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so

#打开mod_rewrite
RewriteEngine On
#开启Log(用于调试)
RewriteLog "logs/rewrite.log"
RewriteLogLevel 9
#只将siteX,demo,support开头的域名做Rewrite
RewriteCond %{SERVER_NAME} ^(site|demo|support) [NC]
#在URI前面加上主机名
RewriteRule ^(.+) %{SERVER_NAME}$1 [C]
#将这台服务器的所有xxx.TA.com/*转到xxx.TB.com/*
RewriteRule  ^([a-z0-9]+)\.([0-9a-z\.]+)/(.*)  http://$1\.TB\.com/$3 [NC,R,L][/code]

如果Apache配置了虚拟主机的话,这个配置应写入默认虚拟主机的配置。

mod_gzip on Windows

[不指定 2006/12/20 18:33 | by ipaddr ]
This one was a difficult one to Google through (kept finding old 1.3 Apache stuff), even though the process itself is pretty quick, so I thought I'd record what I did to get mod_gzip running on Apache 2.0.48 for Windows.

1) Downloaded the zip file with the built DLL from Index of /development/apache/httpd-2.0/win32/modules
2) copied mod_gzip.so into my Apache modules directory
3) copied the settings from my_cfg.txt (contained in the zip file) into my httpd.conf
4) Got a copy of zlib.dll. Placed this in my apache bin directory.
5) Restarted the server

Web Page Analyzer verified that gzip was working and also reports that I'm about 50K lighter on the HTML (20K versus 70K).

分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]