APACHE的伪静态设置

1、配置httpd.conf

 

1 #LoadModule rewrite_module modules/mod_rewrite.so  开启
2 
3      LoadModule rewrite_module modules/mod_rewrite.so
4 
5    #Include conf/extra/httpd-vhosts.conf 开启
6 
7      Include conf/extra/httpd-vhosts.conf

2、配置conf/extra/httpd-vhosts.conf

 1 <VirtualHost 127.0.0.1:80>
 2 
 3   ServerAdmin webmaster@dummy-host.example.com
 4   DocumentRoot "D:/myphpwork/wamp/www"
 5   ServerName localhost
 6   ServerAlias www.dummy-host.example.com
 7   ErrorLog "logs/dummy-host.example.com-error.log"
 8   CustomLog "logs/dummy-host.example.com-access.log" common
 9 
10   #重写规则
11   RewriteEngine on
12 
13   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}!-d
14 
15   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}!-d
16   RewriteRule ^/test/([1-9]+).html$ /test.php?id=$1
17  </VirtualHost>

3、通过编写规则,访问www目录下的test.php文件:localhost/test/2.html 就等同于 localhost/test.php?id=2了

4、因为配置了RewriteCond选项所以,就算是访问真正的www/test/2.html也是正常的2.html而不是伪静态页面localhost/test.php?id=2