Question

I would like to redirect the following as an example:

A.olddomain.com.au/blah.html  >  A.newdomain.com/blah.html
B.olddomain.com.au/blah.html  >  B.newdomain.com/blah.html

Essentially, I have a variable number of subdomains and I only want to change the domain name itself on the redirect.

Any clues or suggestions to try out?

Thanks.

Was it helpful?

Solution

This should work for the HTTP case

RewriteCond %{HTTP_HOST} (.*)\.olddomain\.com\.au
RewriteRule (.*) http://%1.newdomain.com/$1

If you use both HTTP and HTTPS you'd have to use two set of rules, one for HTTP and the other for HTTPS

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} (.*)\.olddomain\.com\.au
RewriteRule (.*) https://%1.newdomain.com/$1

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (.*)\.olddomain\.com\.au
RewriteRule (.*) http://%1.newdomain.com/$1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top