Lawrence Cooke
Lawrence Cooke

Reputation: 1597

301 redirect from another domain

WE have a whole bunch of subdomains from another domain that are pointing to our server. So I am trying to do a 301 redirect from any subdomain at that domain to point to ours

eg.

sub1.domain.com 301 redirect to ourdomain.com sub2.domain.com 301 redirect to ourdomain.com

There could be any number of subdomains pointing to it.

What should the 301 redirect look like for this?

I have this:

RewriteCond %{HTTP_HOST} *\.domain\.net\.au$ [NC]
RewriteRule ^ https://ourdomain.com%{REQUEST_URI} [R=301,L,NE]

but this returns a internal error, if I replace the * with an actual domain it sort of works.

PArt two of this question is about https, our site is always https, when you click on a link in google that goes to one of these domains, its tries to take them to https://sub1.domain.com

Even when I put in the redirect , it still tries to go to https://sub1.domain.com, which causes the browser to give a "this is not safe" error, is there any way via the 301, to make it so it goes directly to our domain without it giving the https error on the other domain first?

Upvotes: 1

Views: 168

Answers (1)

user2493235
user2493235

Reputation:

Here is part one:

RewriteCond %{HTTP_HOST} [^.]+\.domain\.net\.au$
RewriteRule ^ https://ourdomain.com%{REQUEST_URI} [R=301,L]

As for part two, no, that can't be done. HTTPS certificate negotiation has to happen before the connection is established to issue the redirect. All you can do is get a wildcard SSL certificate or provide a valid certificate for the subdomains in some other way. It can't be done without a valid certificate unless you accept the "not safe" errors, which most visitors won't. But once the redirects are in place for a while, the listings will be dropped by Google anyway.

Upvotes: 1

Related Questions