apache 301重定向配置的例子

Apache下301重定向代码(WINDOWS 2003 + APACHE 本文仅限APACHE服务器使用。) 

新建. htaccess文件,输入下列内容(需要开启mod_rewrite): 

1)将不带WWW的域名转向到带WWW的域名下 
Java代码 
  1. Options +FollowSymLinks  
  2. RewriteEngine on  
  3. RewriteCond %{HTTP_HOST} ^jbxue.com [NC]  
  4. RewriteRule ^(.*)$ http://www.jbxue.com/$1 [L,R=301]  
2)重定向到新域名 
Java代码 
  1. Options +FollowSymLinks  
  2. RewriteEngine on  
  3. RewriteRule ^(.*)$ http://www.jbxue.com/$1 [L,R=301]  
3)使用正则进行301重定向,实现伪静态 
Java代码 
  1. Options +FollowSymLinks  
  2. RewriteEngine on  
  3. RewriteRule ^news-(.+)\.html$ news.php?id=$1  
将news.php?id=123这样的地址转向到news-123.html 

Apache下vhosts.conf中配置301重定向 

为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为: 
Java代码 
  1. <VirtualHost *:80>  
  2. ServerName www.jbxue.com  
  3. DocumentRoot /home/fari001Com  
  4. </VirtualHost>  
  5.   
  6. <VirtualHost *:80>  
  7. ServerName jbxue.com  
  8. RedirectMatch permanent ^/(.*) http://www.jbxue.com/$1  
  9. </VirtualHost>  

猜你喜欢

转载自bluesky2013.iteye.com/blog/2034340