apache 和 nginx 301重定向配置方法
Linux 2010-01-21 23:57:46 閱讀 237 評(píng)論 0 字號(hào): 大 中 小
凡是SEO人都知道301重定向的好處吧,它不同于302、meta、Javas<wbr></wbr>cript的跳轉(zhuǎn),是對(duì)搜索引擎友好的永久性跳轉(zhuǎn)方式。
不多說,自己去Google一下吧,下面說一下301重定向?qū)崿F(xiàn)方式:
實(shí)現(xiàn)301跳轉(zhuǎn)可以從程序級(jí)來實(shí)現(xiàn),比如PHP的header函數(shù),實(shí)現(xiàn)方式GOOgle一下吧。
也可以從Web服務(wù)器級(jí)來實(shí)現(xiàn),使用Rewrite模塊即可。
將不帶WWW的主域名重定向到帶WWW的二級(jí)域名,實(shí)現(xiàn)兩個(gè)域名合并,方法如下:
Apache虛擬主機(jī)配置:
<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,單獨(dú)給yoursite.com做一個(gè)虛擬主機(jī)
server {
??? server_name? yoursite.com ;
??? rewrite ^(.*) http://www.yoursite.com$1 permanent;
}
?
(完)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
