最近剛好碰到有需要把舊網站,轉址到新網站。

為了要一次把所有連結轉到新網站。發現可以直接從 .htaccess 來處理

參考:https://linchpinseo.com/htaccess-rules/

Common 301 Redirect Htaccess Rules

How do you redirect a single page? 如果要單純轉址一個頁面

Redirect 301 /pagename.php http://www.domain.com/pagename.html

How do you redirect an entire site or domain to a new one? 如果要整個網站轉址

Redirect 301 / http://www.domain.com/

How do you redirect an entire site to a sub folder? 如果要轉址到新網站的子目錄下

Redirect 301 / http://www.domain.com/subfolder/

How do you use rewriting to redirect from an old domain to a new domain? 如果要轉址到新網站,但路徑不變似乎是可以使用這個

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]