apache 域名跳转
更改虚拟主机配置文件
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<IfModule mod_rewrite.c> # 用到rewrite_module动态模块,要确保Apache中有此模块service httpd -M
RewriteEngine on # 开启rewrite模块
RewriteCond %{HTTP_HOST} ^www.test.com$ #跳转条件
RewriteRule ^(.*)$ http://www.ping.com/$1 [R=301,L] # 跳转目标域名 301为状态码(永久重定向) L:只跳一次last
</IfModule>
# 存在多个域名跳转时,将原来的RewriteCond %{HTTP_HOST} ^www.test.com$ 换为
RewriteCond %{HTTP_HOST} ^www.test1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.test2.com$
# [OR] 为或者,不加默认为且
重读配置文件
# 检查配置文件
/usr/local/apache2/bin/apachectl –t
# 重新加载配置文件
/usr/local/apache2/bin/apachectl graceful
最后更新于
这有帮助吗?