Apache服务器的301重定向

Date 03月 5, 2008

01重定向:abc.com到www.abc.com

 

  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteCond %{HTTP_HOST} !^www.abc.com$ [NC]
  4. RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]

或者

 

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^abc\.com
  4. RewriteRule ^(.*)$ http://www.abc.com/$1 [R=permanent,L]

或者

 

  1. Options +FollowSymLinks
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
  4. RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

301重定向:www.abc.com 到 abc.com

 

  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteCond %{HTTP_HOST} !^abc.com$ [NC]
  4. RewriteRule ^(.*)$ http://abc.com/$1 [L,R=301]

301重定向:单个页面的301转向

 

  1. Redirect 301 /a.html http://www.xyz.com/b.html

Apache配置中实现301转向

 

  1. <VirtualHost xxx.xxx.xxx.xxx>
  2. ServerName domain.com
  3. DocumentRoot /home/domain/www
  4. </VirtualHost>
  5. <VirtualHost xxx.xxx.xxx.xxx>
  6. ServerName www.domain.com
  7. Redirect 301 / http://domain.com/
  8. </VirtualHost>

给这篇文章发表留言