在apache的conf文件中,打开httpd.conf
去掉下面的注释
LoadModule rewrite_module modules/mod_rewrite.so
###################################################
<VirtualHost *:80>
DocumentRoot “/var/www/html/y80h”
ServerName www.y80h.com
ServerAlias y80h.com
<Directory “/var/www/html/y80h”>
allow from all
Options +Indexes
</Directory>
RewriteEngine On
RewriteCond %{http_host} ^y80h.com [NC]
RewriteRule ^(.*)$ http://www.y80h.com [L,R=301]
#这样设置无论访问y80h.com/xxxx/xxxx的页面,都只跳到www.y80h.com首页
</VirtualHost>
将输入 www.xxoo.com 的域名时跳转到www.xyz.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.xxoo.com [NC]
RewriteRule ^(.*) http://www.xyz.com/ [L]
上面这两种方法只会跳到首页,如果想从目录跳到目录,要这样。。。。
<VirtualHost *:80>
DocumentRoot /var/www/domains/www.1234.com
ServerName www.1234.com
ServerAlias 1234.com
<Directory /var/www/domains/www.1234.com>
AllowOverride All
</Directory>
RewriteEngine On
RewriteCond %{http_host} ^www.1234.com [NC]
RewriteRule ^(.*)$ http://www.456.com$1 [L,R=301]
RewriteCond %{http_host} ^1234.com [NC]
RewriteRule ^(.*)$ http://www.456.com$1 [L,R=301]
</VirtualHost>
这样访问原来网站的任何连接,都会跳到新域名的对应该链接上
(责任编辑:IT) |