Apache域名跳转实验
一、实验条件:
- 虚拟主机正常访问:
<virtualhost 192.168.3.99:80>
servername www.sina.com
documentroot /var/www/html/sina/
</virtualhost>
<virtualhost 192.168.3.99:80>
servername www.sohu.com
documentroot /var/www/html/sohu/
</virtualhost>
- apache主配置文件中开放重写模块支持:
LoadModule rewrite_module modules/mod_rewrite.so
二、实验步骤:
1.修改虚拟主机配置文件,加入:
<Directory “/var/www/html/sohu”>
Options Indexes FollowSymlinks
AllowOverride All
Require all granted
2.在"/var/www/html/sohu"中创建.htaccess文件:
vim .htaccess
#开启重写
RewriteEngine on
#设置重写条件
Rewritecond %{HTTP_HOST} ^www.sohu.com
#满足重写条件后,执行重写:
RewriteRule ^(.*)$ http://www.sina.com/$1 [R=permanent,L]
3.systemctl restart httpd
4.验证实验结果:
实验成功!