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;
}
?
(完)
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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