iis 重定向301和错误页面404等设置http://phpwind.me/298.html
apache 重定向301和错误页面404等设置http://phpwind.me/299.html
nginx 重定向301和错误页面404等设置http://phpwind.me/300.html
apache的配制文件http.conf,里面找到
- <VirtualHost *:80>
- ......
- </VirtualHost>
区域,在里面加入
- <IfModule mod_rewrite.c>
- RewriteEngine On
- Options +FollowSymLinks
- RewriteCond %{HTTP_HOST} ^phpwind.me$
- RewriteRule ^(.*)$ http://www.phpwind.me/$1 [R=301,L]
- </IfModule>
如果想使用.htaccess文件,需要开启mod_rewrite,另外把AllowOverride改成ALL
1)将不带www的域名转向到带www的域名下
- Options +FollowSymLinks
- RewriteEngine on
- RewriteCond %{HTTP_HOST} ^phpwind.me [NC]
- RewriteRule ^(.*)$ http://www.phpwind.me/$1 [L,R=301]
2)重定向到新域名
- Options +FollowSymLinks
- RewriteEngine on
- RewriteRule ^(.*)$ http://www.phpwind.me [L,R=301]
3)使用正则进行301转向,实现伪静态
- Options +FollowSymLinks
- RewriteEngine on
- RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
将read.php?tid=2这样的地址转向到read-tid-htm-2.html
Apache下vhosts.conf中配置301重定向,这也是一种方法,即新建一个主机
- <VirtualHost *:80>
- ServerName DocumentRoot /home/www
- </VirtualHost>
- <VirtualHost *:80>
- ServerName phpwind.me
- RedirectMatch permanent ^/(.*) $1
- </VirtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。