[英]How to Blanket Redirect all URL's to Different Domain Sub-directory no Mask
.htaccess規則
Redirect 301 "/page-1/" "https://www.newdomain.com/page-1/"
Redirect 301 "/anotherpage/run/" "https://www.newdomain.com/anotherpage/run/"
Redirect 301 "/" "https://www.newdomain.com/subdirectory/"
當前結果
前兩個規則是特定頁面,效果很好。 問題在於捕獲所有將在目標URL上進行URI的操作。 只需要將指定URI規則以外的任何內容添加到新域子目錄的301。
例如。
https://olddomain.com/page-5/ to https://www.newdomain.com/subdirectory/
預期成績
https://olddomain.com/page-1/ redirects to https://www.newdomain.com/page-1/
https://olddomain.com/anotherpage/run/ redirects to https://www.newdomain.com/anotherpage/run/
https://olddomain.com/anypage/fun/ redirects to https://www.newdomain.com/subdirectory/
我嘗試了幾次重寫規則,但沒有運氣。 它攜帶完整的URI到新域。
RewriteRule ^(.*)$ https://www.newdomain.com/subdirectory/$1 [R=301,L]
在olddomain.com .htaccess文件頂部檢查此規則
<IfModule mod_rewrite.c>
RewriteEngine On
# custom rewrites
RewriteRule ^page-1/$ https://www.newdomain.com/page-1/ [R=301,L]
RewriteRule ^anotherpage/run/$ https://www.newdomain.com/anotherpage/run/ [R=301,L]
# rewrite all not custom matched requests to https://www.newdomain.com/subdirectory/
RewriteRule ^(.*)$ https://www.newdomain.com/subdirectory/ [R=301,L]
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.