apache 301 重定向举例

发表时间:2018-10-16 17:44 | 分类:Linux | 浏览:901 次

Apache下301重定向代码
新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

1)将不带WWW的域名转向到带WWW的域名下 

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

2)重定向到新域名 

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^(.*)$ http://www.nbhao.org/$1 [L,R=301]

3)使用正则进行301重定向,实现伪静态 

  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中配置为: 

  1. <VirtualHost *:80>
  2. ServerName www.nbhao.org
  3. DocumentRoot /home/nbhao.org
  4. </VirtualHost>
  5. <VirtualHost *:80>
  6. ServerName nbhao.org
  7. RedirectMatch permanent ^/(.*) http://www.nbhao.org/$1
  8. </VirtualHost>

 

本文标签:

本文链接:https://www.sijitao.net/2790.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.