原理

通过对通配符匹配到的条件进行重定向,实现访问的控制。

配置

  1. #httpd服务默认加载了rewrite模块
  2. #在conf.module.d/00-base.conf中
  3. #如下内容:LoadModule rewrite_module modules/mod_rewrite.so
  4. <VirtualHost 192.168.25.130:80>
  5. ServerAdmin www.apache1.com
  6. DocumentRoot "/var/www/html/apache1"
  7. ServerName www.apache1.com
  8. ServerAlias www.apache1.com
  9. #重定向开关
  10. RewriteEngine on
  11. RewriteCond %{HTTP_HOST} www.apache1.com [NC]
  12. RewriteRule ^(.*)/index.html$ http://www.apache1.com/rw.html [L]
  13. ErrorLog "logs/apahce1.com-error_log"
  14. CustomLog "logs/apache1.com-access_log" common
  15. </VirtualHost>
  16. echo "<h1>www.apache1.com</h1>" > /var/www/html/apache1/index.html
  17. echo "<h1>you are rewrited by me</h1>" > /var/www/html/apache1/rw.html

image.png

image.png