> For the complete documentation index, see [llms.txt](https://lack.gitbook.io/operation-and-maintenance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lack.gitbook.io/operation-and-maintenance/xu-ni-hua/apache-yu-ming-tiao-zhuan.md).

# apache 域名跳转

更改虚拟主机配置文件

```bash
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>
```

```bash
# 存在多个域名跳转时,将原来的RewriteCond %{HTTP_HOST} ^www.test.com$ 换为

RewriteCond %{HTTP_HOST} ^www.test1.com$ [OR]             
RewriteCond %{HTTP_HOST} ^www.test2.com$

# [OR] 为或者，不加默认为且
```

重读配置文件

```bash
# 检查配置文件
/usr/local/apache2/bin/apachectl –t
# 重新加载配置文件
/usr/local/apache2/bin/apachectl graceful
```
