Home » Apache初级应用 » 泛域名与mod_rewrite
泛域名与mod_rewrite
2009-02-12 15:03:14 | 才被看了237次 | 要评论?
分类: Apache初级应用 | 发布: OurApache | 来源:明分空分
Tags: mod_rewrite,域名
注:文档中的域名及地址为虚构
目的:动态解析home.sst.cn的下级域名,username.home.sst.cn,实现基于虚拟域名(动态域名)的个人空间访问 。
实现步骤:
1.DNS的泛域名解析
20050817 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS ns.sst.cn.
…………………………………………
home IN A 123.123.123.123
*.home IN A 123.123.123.123
以上是在unix bind9下的设置,在windows server中的DNS设置与之同理,略。
2. web服务的设置
a) 如果是IIS,只需要在IIS中设置一个空的主机头,然后置一跳转文件,例:
[asp代码片断]
temp1 = Request.ServerVariables(“HTTP_HOST”)
temp2 = Right(Request.ServerVariables(“HTTP_HOST”),12) ‘其中12表示你的域名去掉前辍后剩下的字符数.
temp3 = Replace(temp1,temp2,”")
%>
<%if temp3 <> “www” then
Response.Redirect “http://home.sst.cn/index.asp?name=” & temp3 %>
<%end if%>
b) 如果是Apache,则修改httpd.conf文件加入虚拟主机(如果需要同时供应多个web服务)
ServerAdmin zhao@home.sst.cn
DocumentRoot /somewhere/to/wwwhome
ServerName home.sst.cn
ServerAlias *.home.sst.cn
ErrorLog logs/home.sst.cn/error_log
CustomLog logs/home.sst.cn/access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName anotherweb.sst.cn
DocumentRoot /somewhere/to/anotherweb
</VirtualHost>
为改变虚拟主机顺序,使提供泛域名的web服务为非中心主机(main host),加入此句:
ServerAlias *.home.sst.cn
分析访问过程:
用户输入[username].home.sst.cn
|
|
|
`-->apache分析主机头的值,不匹配任何一
个虚拟主机名,则交送中心主机的目录
|
|
|
接下来应该有两种方法处理:<--'
|
|
^
' `
/ \
① 在home.sst.cn的根目录 ② 用mod_rewrite重写
设跳转文件,ASP代码举例: URL指向[username]目录。
| |
| |
| |
方法①纯代码方式,无用户目录。
方法②用mod_rewrite重写URL,指向用户目录。
在blog的主目录下建立.htaccess文件,内容为:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteRule ^(.*)/home/(.*)$ $1.php?$2
</IfModule>
