I’ve recently migrated everything from an old website to a new website, and I’m trying to make redirects so that typing https://www.oldsite.com (and other variations like http://www.oldsite.com, https://oldsite.com and http://oldsite.com) automatically go to https://www.newsite.com.
I’ve successfully made a .htaccess file that does everything I need (including http://www.oldsite.com redirecting to https://www.newsite.com), but the only part I cannot do is make https://www.oldsite.com or any subpages (https://www.oldsite.com/*) redirect to the equivalent page on the new site (the page structures on both sites are identical, just different domain names).
I’ve had to log into GoDaddy and create manual redirects for the important pages (which automatically generated most of the code), hence why the code I’m going to show seems long. Also, the way my 2 domains are set up is that the old site is now an ‘add-on domain’ of the new site, meaning there’s a folder in the main site that contains the new site, each with separate htaccess files.
How can I fix these redirects? I’ve tried a lot of tweaks which haven’t got everything working.
Here’s the .htaccess code for the new site (parent directory of the old site - it might be only the first 5 lines or so that do it as most of the code is just each manual redirect automatically generated from 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]
And here’s the .htaccess code for the old site (again, maybe just the first 5 lines or so):
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]
Any suggestions would be much appreciated here as I’m baffled, thank you.
Note: I think the parent .htaccess file affects the child .htaccess file.
Also: a better way of explaining this would be I just want any url variation of oldsite.com to go to the same variation of newsite.com (e.g. https://www.oldsite.com/somepage.html would redirect to https://www.newsite.com/somepage.html, so only oldsite is replaced with newsite).
You can insert this rule just below RewriteEngine On line:
RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldsite\.com$ [NC]
RewriteRule ^ https://www.newsite.com%{REQUEST_URI} [L,R=301,NE]
Also as a side note you can replace everywhere these 2 lines:
RewriteCond %{HTTP_HOST} ^oldsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
With this single conditions:
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldsite\.com$ [NC]
newbie on htaccess and redirects, I hope someone can help me with this. At the moment all but one http urls are redirecting correctly to https.
The following script has been updated as requested to remove the duplicate, the problem still persists.
Examples followed:
http://example.com redirects to https://www.example.com/
http://www.example.com redirects to https://www.example.com/
http://subdomain.example.com redirects to https://subdomain.example.com
Trouble comes when
http://example.com/somepage this only redirects to https://www.example.com/
Following is a snip from my htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^admin$ admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*\.php)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . index.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is a valid way of redirecting all non https:// calls to their secure versions. Using this would redirect http://example.com/somepage to https://www.example.com/somepage
Perhaps your 301 is just cached? Clear your cache and try again. I would recommend using [R=302] flags until you confirm the redirects are working and then update your .htaccess to use 301's.
I have this .htaccess
RewriteEngine on
RewriteBase /
# To force CN to use https
RewriteCond %{HTTP_HOST} ^jobs.connectnigeria\.com [NC]
RewriteCond %{SERVER_PORT} 80
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://jobs.connectnigeria.com/$1 [R,L]
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
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 ^.*$ - [L]
#RewriteCond %{HTTP_HOST} !^www\.(.*)
#RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
# dont rewrite if there was posted here!
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !\.html?$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
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 ^(.*[^/])$ $1/ [L,R=301]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
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.php?/$1 [L,QSA]
#RewriteRule ^(.*)$ index.php/$1 [L,QSA]
<FilesMatch ".(eot|ttf|otf|woff|woff2)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
#User-agent: *
#Disallow: /
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php54” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php54 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
As you can see, I have this
<FilesMatch ".(eot|ttf|otf|woff|woff2)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
but still showing me this error
any help, ideas please?
cnmain.connectnigeria.com should set Access-Control-Allow-Origin header for the font to either * or jobs.connectnigeria.com. You are doing it on jobs.connectnigeria.com.
I have this code in htaccess to redirect all sub-domains to the main domain
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I want to exclude some sub-domains like test.example.com so I edited the code like this
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^test\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
But it doesn't work it redirects the test.exmple.com to the main domain example.com/test
So how to edit this code to exclude test from the redirection
To match domain name you need to use variable HTTP_HOST:
RewriteCond %{HTTP_HOST} !^test\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,NE,L]
I don't know what i've done wrong here but can someone look at my .htaccess code and work out why I keep have duplicate content with a trailing /
I just want to redirect all http to https without www and its duplicating my content.
Im running my site on Concrete5
.htaccess code here
RewriteOptions inherit
# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://defrae.com%{REQUEST_URI} [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.defrae.com [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://defrae.com%{REQUEST_URI} [L,R=301,NC]