301 / 302 Redirects 重定向轉址

301 及 302 這兩種形式的重定向 (Redirects) 都會將網站從一個 URL 或網頁發送到另一個 URL 或網頁。

301 和 302 的差別:

  • 301 重定向表示網頁已經永久移動到新位置 (網址)。
  • 302 重定向表示網頁已經移動到新位置 (網址),但這只是暫時的。

接到一個很特殊的 WordPress 網站,客戶希望網站「首頁」 302 重定向到另一個網址。

但是,WordPress 後台 wp-admin 登入網址維持原網址,不要重定向。

使用 Regular 規則

在 Kinsta 的後台 Redirects 的規則寫法:

  • Domain:原本的網址 www.example.com
  • Redirects From:^/?$
  • Redirects To:你的目標網址 (後面不可加上 &1) https://example.com
  • Status Code:302

這樣的規則,只有首頁網址重定向,其他的頁面保持不變。

另一種最常用的規則,網站更換域名,舊網址重定向到新域名。

  • Domain:舊網址 www.example.com
  • Redirects From:^(.*)$
  • Redirects To:你的新網址 https://example.com$1
  • Status Code:301

9/2 日補充:

Google Search Central 在 Twitter 上發佈一個說明,平息一個 301 / 302 的謠言。

302 or 301: For maximum PageRank
It doesnt matter!
Use the technically correct redirect type
It can also be a 307 308
Search engines have dealt with redirects since the beginning
if an SEO tells you that 302 redirects are bad,
Send them here.
Want more?
Check out our videos & docs about HTTP status codes!

Written By Human

發佈留言

Your Mastodon Instance