views:

260

answers:

1

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.

+4  A: 

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
Vinko Vrsalovic
Worked perfectly the first time. Thanks for that. I assume from your answer that a %1 .. %n is matched from the RewriteCond and $1 .. $n is matched from the URL?
Carl
@Carl: Exactly as listed at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
Gareth
Nice, didn't realise you could do that. :-)
ceejayoz