虽然很多域名提供商均支持url转发,但是有时我们需要自己实现转发,以下为自己工作中遇到的问题,特别上
1,用.htaccess来实现
在apache配置文件内或虚拟主机配置文件内 开启AllowOverride(all)
<Directory /www/users/xxx>
AllowOverride all
</Directory>
在/www/users/xxx目录下创建。htaccess文件 写入
Redirect permanent / http://www.baidu.com
会把访问到当先目录(/www/users/xxx)的访问全转达 www.baidu.com网站首页,起缺点为:加上单签域名
为ttl289.cn ,它不能输入ttl289.cn/adfasdf ,会报错,出现404无法找到该页的错误
2,使用urlrewrite这个模块,
首先要检查是否已经开启了转发模块
LoadModule rewrite_module     libexec/mod_rewrite.soAddModule mod_rewrite.c
其次在apache配置文件内或虚拟主机配置文件内 开启AllowOverride(all)
<Directory /www/users/xxx>
AllowOverride all
</Directory>
在/www/users/xxx目录下建立一个.htaccess的文件,该文件要能被访问,写入:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.ttl289\.cn$ [NC]
RewriteRule ^(.*)$ http://www.baidu.com/ [R=301,L]
www.ttl289./cn内的所有连接均转发到 www.baidu.com的首页文件。如www.ttl289 .cn/asdf/asdf均能转
此弥补了第一种缺点。
3,
如果在/var/log/http/error_log中看到如下错误
[Fri Sep 12 13:18:16 2008] [alert] [client 1.1.1.1] /www/users/ttl289.net/.htaccess: order not allowed here
[Fri Sep 12 13:18:18 2008] [alert] [client 1.1.1.1] /www/users/ttl289.net/.htaccess: order not allowed here
[Fri Sep 12 13:18:22 2008] [alert] [client 1.1.1.1] /www/users/ttl289.net/.htaccess: order not allowed here
[Fri Sep 12 13:22:16 2008] [alert] [client 1.1.1.1] /www/users/ttl289.net/.htaccess: order not allowed here
则您少添加了一些参数,如你添加的只是AllowOverride Options FileInfo
则需要将AllowOverride Options FileInfo 再添加上Indexes Limit AuthConfig
IndexIgnore 对应的是 Indexes
order       对应的是 Limit     
AuthName    对应的是 AuthConfig  
或如1 2 那样直接将AllowOverride All