原理
通过对通配符匹配到的条件进行重定向,实现访问的控制。
配置
#httpd服务默认加载了rewrite模块
#在conf.module.d/00-base.conf中
#如下内容:LoadModule rewrite_module modules/mod_rewrite.so
<VirtualHost 192.168.25.130:80>
ServerAdmin www.apache1.com
DocumentRoot "/var/www/html/apache1"
ServerName www.apache1.com
ServerAlias www.apache1.com
#重定向开关
RewriteEngine on
RewriteCond %{HTTP_HOST} www.apache1.com [NC]
RewriteRule ^(.*)/index.html$ http://www.apache1.com/rw.html [L]
ErrorLog "logs/apahce1.com-error_log"
CustomLog "logs/apache1.com-access_log" common
</VirtualHost>
echo "<h1>www.apache1.com</h1>" > /var/www/html/apache1/index.html
echo "<h1>you are rewrited by me</h1>" > /var/www/html/apache1/rw.html