關於網站如何做 301 跳轉,網上答案與方法不少,卻大同小異,想找到真正適合自己的並不容易。以下做個簡單總結,希望能幫到大家。
Linux 下 301 重定向設置
1. 將下面的代碼復制到 .htaccess 文件中並保存。
(單個域名跳轉)
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} ^seozyw.com [NC]
RewriteRule ^(.*)$ https://www.seozyw.com/$1 [L,R=301]
多個域名跳轉
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} ^www.1678tv.net [NC]
RewriteRule ^(.*)$ https://www.seozyw.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.1678tv.com [NC]
RewriteRule ^(.*)$ https://www.seozyw.com/$1 [L,R=301]
或者
RewriteCond %{http_host} ^www\.1\.com.* [OR]
RewriteCond %{http_host} ^1\.com.* [OR]
RewriteCond %{http_host} ^2\.com.*
RewriteRule ^(.*)$ https://www.2.com/$1 [L,R=301]
2. 將 .htaccess 文件上傳至站點根目錄下。
IIS 7 的 301 重定向代碼,加到 web.config 裡:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Enforce canonical hostname" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www.seozyw.com$" />
</conditions>
<action type="Redirect" url="https://www.seozyw.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="index.asp" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
轉載請註明文章來源:seo資源網搜集整理。