Apache下url重写,虚拟机设置

来源:互联网 发布:js电机 编辑:程序博客网 时间:2024/05/17 00:13
1.http://www.linuxsir.org/main/node/293
在httpd里打开mod_rewrite.so模块
2.在需要重写的网站目录下建立.htaccess文件
3.ErrorDocument 404 /notfound.html
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f   //判断文件是否存在,不存在才执行重写
    RewriteCond %{REQUEST_FILENAME} !-d   //判断目录是否存在,不存在才执行重写
    RewriteRule ^(.*)[.]html$ $1.php
</IfModule>
记得需要取用的字符串用()括起来,然后后面才能$1来取用

正则参考http://deerchao.net/tutorials/regex/regex.htm



NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/wamp/www/"
    ServerName localhost
    ServerAlias localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/wamp/www/test/"
    ServerName test
    ServerAlias test
</VirtualHost>