论坛风格切换
  • 5060阅读
  • 1回复

[apache]apache 重定向301和错误页面404等设置 [复制链接]

上一主题 下一主题
离线太史慈
 

发帖
766
金币
626
威望
556
只看楼主 倒序阅读 使用道具 楼主  发表于: 2011-07-20
— 本帖被 云天河 执行加亮操作(2011-07-20) —
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,里面找到
  1. <VirtualHost *:80>
  2. ......
  3. </VirtualHost>
区域,在里面加入
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. Options +FollowSymLinks
  4. RewriteCond %{HTTP_HOST}   ^phpwind.me$
  5. RewriteRule ^(.*)$ http://www.phpwind.me/$1 [R=301,L]
  6. </IfModule>


如果想使用.htaccess文件,需要开启mod_rewrite,另外把AllowOverride改成ALL

1)将不带www的域名转向到带www的域名下
  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^phpwind.me [NC]
  4. RewriteRule ^(.*)$ http://www.phpwind.me/$1 [L,R=301]

2)重定向到新域名
  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^(.*)$ http://www.phpwind.me [L,R=301]
3)使用正则进行301转向,实现伪静态
  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
将read.php?tid=2这样的地址转向到read-tid-htm-2.html

Apache下vhosts.conf中配置301重定向,这也是一种方法,即新建一个主机
  1. <VirtualHost *:80>
  2. ServerName DocumentRoot /home/www
  3. </VirtualHost>
  4. <VirtualHost *:80>
  5. ServerName phpwind.me
  6. RedirectMatch permanent ^/(.*) $1
  7. </VirtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。



[url=http://www.phpwind.com]phpwind[/url]
离线太史慈

发帖
766
金币
626
威望
556
只看该作者 沙发  发表于: 2011-08-14
实例
在apache中我们要把phpwind.me跳转到www.phpwind.me

RewriteEngine on
RewriteCond %{HTTP_HOST} ^phpwind.me [NC]
RewriteRule ^(.*)$ http://www.phpwind.me [L,R=301]
[url=http://www.phpwind.com]phpwind[/url]
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
提到某人:
选择好友
上一个 下一个