Redirect HTTPS to HTTP on Apache

.htaccessApache2httphttpsssl-certificate

I have a main domain and a couple of secondary domains hosted by a commercial web hosting service using Apache servers. Each domain has its own .htaccess file. I have only one SSL certificate, which is all I need, for the main domain.

However, if I type in the URL box (or a search engine directs to) HTTPS://secondarydomain.com, I get the web page warning about an invalid security certificate. When I confirm the exception, the browser displays the maindomain that is bound to the certificate. I read the post: SSL priority. Is there nothing at all that I can do in this scenario to redirect from HTTPS to HTTP for the secondary domains?

EDIT for clarification: I want the server to apply SSL certificate only to the main domain. The sub-domains are wholly unrelated domains. It is only confusing to people visiting those sub-domains to see a SSL certificate with the name of an unrelated website. That is why I was hoping there was something I could put in the .htaccess files of those subdomains to make the server bypass or ignore the SSL certificate of the main domain.

EDIT: I also tried an unconditional redirect with these lines in .htaccess

RewriteEngine on
Redirect / "http://m y d o m a i n .com/"

Best Answer

We also encountered scenarios before where we had client applications that could not support HTTPS that we needed to redirect back to HTTP. We used the Apache redirect permanent on the virtualhost for HTTPS to force redirection back to HTTP for a particular application.

You might be able to use the following reference which they say works with htaccess: https://httpd.apache.org/docs/2.4/rewrite/remapping.html

Here's a snippet that might help you achieve what you want:

<If "%{SERVER_PROTOCOL} != 'HTTP'">
    Redirect / "http://secondarydomain.com/"
</If>

I haven't tried managing the redirection using htaccess since we use virtualhosts but this seems possible also with htaccess.