将所有页面从站点 A 重定向到站点 B,包括 http 和 https

Posted

技术标签:

【中文标题】将所有页面从站点 A 重定向到站点 B,包括 http 和 https【英文标题】:Redirecting all pages from site A to site B, including http & https 【发布时间】:2019-06-14 03:50:27 【问题描述】:

我最近将所有内容从旧网站迁移到新网站,我正在尝试进行重定向,以便自动输入 https://www.oldsite.com(以及其他变体,如 http://www.oldsite.com、https://oldsite.com 和 http://oldsite.com)转到https://www.newsite.com。

我已经成功创建了一个 .htaccess 文件,它可以满足我的所有需求(包括 http://www.oldsite.com 重定向到 https://www.newsite.com),但我唯一不能做的部分是创建 https://www.oldsite.com 或任何子页面 (https://www.oldsite.com/*)重定向到新站点上的等效页面(两个站点上的页面结构相同,只是域名不同)。

我必须登录 GoDaddy 并为重要页面创建手动重定向(它会自动生成大部分代码),因此我要展示的代码看起来很长。此外,我的 2 个域的设置方式是旧站点现在是新站点的“附加域”,这意味着主站点中有一个包含新站点的文件夹,每个文件夹都有单独的 htaccess 文件。

如何解决这些重定向?我尝试了很多调整,但都无法正常工作。

这是新站点的 .htaccess 代码(旧站点的父目录 - 它可能只是 前 5 行 左右该代码只是从 GoDaddy 自动生成的每个手动重定向):

RewriteOptions inherit

ErrorDocument 404 https://www.newsite.com/other/404-error.html

RewriteEngine On
RewriteCond %HTTP_HOST !^(www\.)?oldsite\.com
RewriteCond %HTTPS off
RewriteCond %REQUEST_URI !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ https://%HTTP_HOST%REQUEST_URI [L,R=301]
RewriteCond %HTTP_HOST ^newsite.com [NC]
RewriteCond %REQUEST_URI !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ https://www.newsite.com/$1 [L,R=301]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^hosting$ "http\:\/\/www\.dpbolvw\.net\/click\-8487961\-11003096" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^checker$ "https\:\/\/www\.newsite\.com\/tools\/domain\-name\-checker\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ecommerce$ "https\:\/\/www\.newsite\.com\/ecommerce\-store\-woocommerce\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\/?$ "https\:\/\/www\.newsite\.com\/ebay\/free\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaypro$ "https\:\/\/www\.newsite\.com\/ebay\/pro\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^other\/ebay\-template\.html$ "https\:\/\/www\.newsite\.com\/ebay\/free\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaycheats$ "https\:\/\/www\.newsite\.com\/ebay\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaycheat$ "https\:\/\/www\.newsite\.com\/ebay\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emprovider$ "https\:\/\/www\.getresponse\.com\/\?a\=oldsite" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailprovider$ "https\:\/\/www\.getresponse\.com\/\?a\=oldsite" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^em$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^email$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emails$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emcheat$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emcheats$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailcheat$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailcheats$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^photography$ "https\:\/\/www\.newsite\.com\/resources\.html\#photography\-tools" [R=301,L]
RewriteCond %HTTP_HOST ^newsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.newsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^photography\.html$ "https\:\/\/www\.newsite\.com\/resources\.html\#photography\-tools" [R=301,L]

这是旧网站的 .htaccess 代码(同样,可能只是前 5 行左右):

RewriteEngine on
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/www\.newsite\.com\/" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^hosting$ "https\:\/\/www\.newsite\.com\/hosting" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^checker$ "https\:\/\/www\.newsite\.com\/tools\/domain\-name\-checker\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ecommerce$ "https\:\/\/www\.newsite\.com\/ecommerce\-store\-woocommerce\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\/?$ "https\:\/\/www\.newsite\.com\/ebay\/free\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaypro$ "https\:\/\/www\.newsite\.com\/ebay\/pro\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^other\/ebay\-template\.html$ "https\:\/\/www\.newsite\.com\/ebay\/free\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaycheats$ "https\:\/\/www\.newsite\.com\/ebay\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebaycheat$ "https\:\/\/www\.newsite\.com\/ebay\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emprovider$ "https\:\/\/www\.newsite\.com\/emprovider" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailprovider$ "https\:\/\/www\.newsite\.com\/emailprovider" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^em$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^email$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emails$ "https\:\/\/www\.newsite\.com\/email\-marketing\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emcheat$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emcheats$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailcheat$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^emailcheats$ "https\:\/\/www\.newsite\.com\/email\-marketing\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^photography$ "https\:\/\/www\.newsite\.com\/resources\.html\#photography\-tools" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^photography\.html$ "https\:\/\/www\.newsite\.com\/resources\.html\#photography\-tools" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.html$ "https\:\/\/www\.newsite\.com\/" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\.html$ "https\:\/\/www\.newsite\.com\/ebay\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\/pro\-template\.html$ "https\:\/\/www\.newsite\.com\/ebay\/pro\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\/free\-template\.html$ "https\:\/\/www\.newsite\.com\/ebay\/free\-template\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ebay\/cheat\-sheet\.html$ "https\:\/\/www\.newsite\.com\/ebay\/cheat\-sheet\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^resources\.html$ "https\:\/\/www\.newsite\.com\/resources\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ecommerce\-store\-woocommerce\.html$ "https\:\/\/www\.newsite\.com\/ecommerce\-store\-woocommerce\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^other\/new\-subscriber\.html$ "https\:\/\/www\.newsite\.com\/other\/new\-subscriber\.html" [R=301,L]
RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$
RewriteCond %REQUEST_URI !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %REQUEST_URI !^/\.well-known/pki-validation/[A-F0-9]32\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^other\/welcome\-back\.html$ "https\:\/\/www\.newsite\.com\/other\/welcome\-back\.html" [R=301,L]

任何建议都会非常感谢,因为我很困惑,谢谢。

注意:我认为父 .htaccess 文件会影响子 .htaccess 文件。

另外:解释这一点的更好方法是我只希望 oldsite.com 的任何 url 变体转到 newsite.com 的相同变体(例如,https://www.oldsite.com/somepage.html 将重定向到 https://www.newsite.com/somepage.html,所以只有 oldsite 被替换与新网站)。

【问题讨论】:

【参考方案1】:

您可以在RewriteEngine On 行下方插入此规则

RewriteEngine On

RewriteCond %HTTPS !on [OR]
RewriteCond %HTTP_HOST ^(?:www\.)?oldsite\.com$ [NC]
RewriteRule ^ https://www.newsite.com%REQUEST_URI [L,R=301,NE]

另外作为旁注,您可以替换 everywhere 这 2 行:

RewriteCond %HTTP_HOST ^oldsite\.com$ [OR]
RewriteCond %HTTP_HOST ^www\.oldsite\.com$

有了这个单一的条件:

RewriteCond %HTTP_HOST ^(?:www\.)?oldsite\.com$ [NC]

【讨论】:

谢谢,但这不起作用。我尝试在 RewriteEngine On 行下方添加此内容: RewriteCond %HTTPS !on [OR] RewriteCond %HTTP_HOST ^(?:www\.)?oldsite\.com$ [NC] RewriteRule ^ newsite.com%REQUEST_URI [L,R=301,NE] 您指的是哪个 .htaccess 文件?我假设旧站点的 htaccess 文件(在新站点的子目录中),但我分别尝试过,但都没有工作 您在旧网站上有多个 .htaccess 吗?如果没有,则应将其放置在旧站点的站点根目录 .htaccess 中。在按照我的建议添加此规则后,还要告诉哪个 URL 不适合您。 旧站点上只有一个 .htaccess 文件(新父站点上只有一个)。任何带有旧站点 https 前缀的 URL 都不起作用(因为它显示 SSL 错误“连接不是私有”消息),但 http 前缀仍然可以。例如,https://www.oldsite.com/ 有 SSL 错误,而 http://www.oldsite.com/ 没有错误并正确重定向到新站点。感谢您的帮助 SSL error 'connection is not private' message) 无法通过重定向规则修复,因为 浏览器和 Web 服务器之间的 SSL 握手发生在重定向模块加载之前,这是出于安全原因。 SSL 警告只能通过在两个站点上放置正确的 SSL 证书来修复。

以上是关于将所有页面从站点 A 重定向到站点 B,包括 http 和 https的主要内容,如果未能解决你的问题,请参考以下文章

使用.htaccess重定向到站点更新的维护页面

oAuth 2 如何工作?

PayPal 和表单订购 HTML

Liferay 7:是不是可以自动从链接站点获取图像到站点地图?

如何将整个站点从 HTTP 重定向到 HTTPS,Drupal 站点中的 2 个页面除外?

转化目标中的 Google Analytics UTM 代码