.htaccess 舊站點重定向到新站點,每個 url 單獨重定向

.htaccess 舊站點重定向到新站點,每個 url 單獨重定向

我有一個網站已遷移到另一個 URL。因此,我想將以前的所有 URL 遷移到具有不同段的新 URL。例如

  1. 主要重定向

    舊網站是:https://myoldsite.abc
    新網站是:https://mynewsite.xyz

  2. 我還想將所有其他頁面重新導向到新 URL

    舊網站是:https://myoldsite.abc/myfolder
    新網站是:https://mynewsite.xyz/new_url_1

    舊網站是:https://myoldsite.abc/myfolder/old_url
    新網站是:https://mynewsite.xyz/new_url_2

    舊網站是:https://myoldsite.abc/myfolder/abc_url
    新網站是:https://mynewsite.xyz/new_url_3

  3. 簡單的 URL

    舊網站是:https://myoldsite.abc/testing_url
    新網站是:https://mynewsite.xyz/New_testing_url_1

我的程式碼看起來像這樣

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^myoldsite.abc [NC,OR]
RewriteCond %{HTTP_HOST} ^www.myoldsite.abc [NC]

RewriteRule ^/myfolder/url_1/?$  https://mynewsite.xyz/new_url_1 [R=301,L]
RewriteRule ^/myfolder/url_2/?$  https://mynewsite.xyz/new_url_2 [R=301,L]
RewriteRule ^/myfolder/url_3/?$  https://mynewsite.xyz/new_url_3 [R=301,L]
RewriteRule ^/myfolder/url_4/?$ https://mynewsite.xyz/new_url_4 [R=301,L]

RewriteRule ^/myfolder?$ https://mynewsite.xyz/new_url_4 [R=301,L,NC] 

RewriteRule ^(.*)$ https://mynewsite.xyz [R=301,L]
</IfModule>

答案1

您的 htaccess 檔案應該可以工作,它應該放置在根目錄中。

您是否嘗試過重定向?

重定向 301 /資料夾/http://www.example.com/new_path/

相關內容