views:

51

answers:

2

I have 5 sites on one apache server. One of the sites is with SSL. So when the other sites are accessed with https then they are redirected to the SSL site which is incorrect.

E.g.

https://x.com (with SSL)

http://y.com (normal site no SSL)

If I access https://y.com then I get the content from x.com. How can I fix so https://y.com just gets rewritten to http://y.com?

A: 

You can define it in apache config file. You must add a rule to connection incoming from https port.

If you are using linux, propably you have this config in /etc/apache2/sites-available/default-ssl.

If you don't have this file you must searching https virtualhost:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
Svisstack
+1  A: 

In your .htaccess put:

RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://y.com/$1 [R=301,L]
bisko
This should do it, however, you will most likely get a certificate related error for the end user since redirecting from https still means making a connection to the host using https, which requires a certificate for the hostname being used. The catch is that you can't have more than one certificate on the same network interface and port combination (since certs are sent before the requested hostname is determined).
Joonas Trussmann
And now that I looked it over once more, I'm not really sure that this rewrite condition will do. You'd more likely need a condition that matches the requested hostname inside your https virtual host, rather than in your regular domains .htaccess.
Joonas Trussmann
If you are trying to escape the Certificate error by moving the statement between files - it won't do :) The certificate is requested before any rewrite rules are fired, so moving it to the virtual host wouldn't help too. As for if this would work at all - it works, but I use it the other way around to get users ON https when it's needed.
bisko