主要利用Apache重写
1:打开httpd.conf,打开
LoadModule rewrite_module modules/mod_rewrite.so
找到AllowOverride None 改成 AllowOverride All,
2:配置虚拟目录
<VirtualHost *:80>
ServerName www.test.net
DocumentRoot "D:\wamp\web\test"
DirectoryIndex index.html index.php
ErrorDocument 404 /404/404show.php
<Directory "D:\wamp\web\test">
Options Indexes FollowSymLinks INCLUDES
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.net [NC]
RewriteRule ^(.*)$ http://www.test.net/$1 [L,R=301]
</Directory>
ErrorLog "logs/test.net.log"
CustomLog "logs/test.net.log" common
</VirtualHost>
方法很多 也可以创建网站根目录下的.htaccess
文件