apache 和 nginx 301重定向配置方法

系统 2067 0
http://jianzi0307.blog.163.com/blog/static/20812002010021115746160/

apache 和 nginx 301重定向配置方法

Linux 2010-01-21 23:57:46 阅读 237 评论 0 字号:

凡是SEO人都知道301重定向的好处吧,它不同于302、meta、Javas<wbr></wbr>cript的跳转,是对搜索引擎友好的永久性跳转方式。

不多说,自己去Google一下吧,下面说一下301重定向实现方式:

实现301跳转可以从程序级来实现,比如PHP的header函数,实现方式GOOgle一下吧。

也可以从Web服务器级来实现,使用Rewrite模块即可。

将不带WWW的主域名重定向到带WWW的二级域名,实现两个域名合并,方法如下:

Apache虚拟主机配置:

<VirtualHost *:80>

        DocumentRoot /da<wbr></wbr>ta/www/www.yoursite.com

        ServerName www.yoursite.com

        DirectoryIndex index.html index.htm  index.php index.shtml

        ErrorDocument 404 http://www.yoursite.com/404.html

</VirtualHost>

 

<VirtualHost *:80>

        ServerName yoursite.com

        RewriteEngine on

        RewriteRule ^(.*)$ http://www.yoursite.com$1 [R=301,L]

</VirtualHost>

 

Nginx配置方法:

方法1:

server {

    server_name www.yoursite.com yoursite.com ;

    if ($host != 'www.yoursite.com' ) {

        rewrite  ^/(.*)$  http://www.yoursite.com/$1   permanent;

    }

    ...

}

 

方法2:

类似apache,单独给yoursite.com做一个虚拟主机

server {

    server_name  yoursite.com ;

    rewrite ^(.*) http://www.yoursite.com$1 permanent;

}

 

(完)



apache 和 nginx 301重定向配置方法


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论