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

时间:2019-01-20 16:15:29

标签: .htaccess redirect mod-rewrite url-rewriting

我最近将所有内容从旧网站迁移到了新网站,并且我尝试进行重定向,以便键入https://www.oldsite.com(以及其他类似http://www.oldsite.comhttps://oldsite.comhttp://oldsite.com)自动转到https://www.newsite.com

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

我必须登录GoDaddy并为重要页面创建手动重定向(该页面会自动生成大部分代码),因此为什么我要显示的代码似乎很长。同样,我的两个域的设置方式是旧站点现在是新站点的“附加域”,这意味着主站点中包含一个包含新站点的文件夹,每个文件夹都有单独的htaccess文件。 / p>

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

以下是新网站的.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的所有网址变体都转到newsite.com的相同变体(例如https://www.oldsite.com/somepage.html会重定向到https://www.newsite.com/somepage.html,所以只有旧站点替换为新站点)。

1 个答案:

答案 0 :(得分: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]

此外,您可以在以下两行中替换任何地方

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

在这种情况下:

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