Michael Sheridan
Michael Sheridan

Reputation: 21

.htaccess to redirect multiple domains, non-www. and non-https to the one single domain and preserve the path

I have a few old domains that resolve to the new site. I just switched on SSL. The old blog posts from old sites have been merged into the new site with the same paths.

I need .htaccess code to redirect multiple domains, non-www. and non-https to the one single domain with www and https. Essentially, if it doesn't begin https://www.mavencomputers.com.au/ then redirect it to that whilst preserving the rest of the path, ie, not redirecting to home.

I currently have

RewriteCond %{HTTP_HOST} ^artisan\-solutions\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.artisan\-solutions\.net\.au$
RewriteRule ^/?$ "https\:\/\/www\.mavencomputers\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mavencomputers\.com\.au$1
RewriteRule ^(.*)$ "https://www.mavencomputers\.com\.au\/%1" [R=301,L]

Upvotes: 2

Views: 82

Answers (1)

Florian Lemaitre
Florian Lemaitre

Reputation: 5748

You can use this .htaccess code:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mavencomputers\.com\.au$
RewriteCond %{HTTP_HOST} !^images\.mavencomputers\.com\.au$
RewriteRule ^(.*)$ https://www.mavencomputers.com.au/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You can test this file with this tool.

Upvotes: 1

Related Questions