Apache中301重定向的配置代码
更新时间:2011年02月24日 00:06:04 作者:
Apache下301重定向代码(因为我使用的是WINDOWS 2003 + APACHE 所以本文仅限APACHE服务器使用。)
新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
1)将不带WWW的域名转向到带WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ https://www.jb51.net/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.baidu.com/$1 [L,R=301]
3)使用正则进行301重定向,实现伪静态
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
将news.php?id=123这样的地址转向到news-123.html
Apache下vhosts.conf中配置301重定向
为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:
<VirtualHost *:80>
ServerName www.baidu.com
DocumentRoot /home/fari001Com
</VirtualHost>
<VirtualHost *:80>
ServerName faribaidu.com
RedirectMatch permanent ^/(.*) http://www.baidu.com/$1
</VirtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。
1)将不带WWW的域名转向到带WWW的域名下
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ https://www.jb51.net/$1 [L,R=301]
2)重定向到新域名
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.baidu.com/$1 [L,R=301]
3)使用正则进行301重定向,实现伪静态
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
将news.php?id=123这样的地址转向到news-123.html
Apache下vhosts.conf中配置301重定向
为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:
复制代码 代码如下:
<VirtualHost *:80>
ServerName www.baidu.com
DocumentRoot /home/fari001Com
</VirtualHost>
<VirtualHost *:80>
ServerName faribaidu.com
RedirectMatch permanent ^/(.*) http://www.baidu.com/$1
</VirtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。
相关文章
关于Windows 不能在 本地计算器 启动 Apache2(phpstudy)
今天在自己的本子上准备放多个虚拟站点。用的是#phpstudy#。在软件自身的站点设置中,根据提示添加的多站点无效不知道是否和我的系统是Win7有关2012-09-09
如何解决win10与Ubuntu16.04时间不同步的问题的方法
本篇文章主要介绍了如何解决win10与Ubuntu16.04时间不同步的问题的方法,非常具有实用价值,需要的朋友可以参考下2017-05-05
红帽RHEL8和7的区别对比分享(Centos8与7参照redhat)
这篇文章主要介绍了红帽RHEL8和7有什么区别(Centos8与7参照redhat),包括红帽RHEL8和RHEL7功能区别对比和RHEL8额外新功能新特性,对红帽RHEL8和7相关知识感兴趣的朋友跟随小编一起看看吧2023-01-01


最新评论