1

I'm new to apache setup and I've encountered a problem. Couple of them actually but this one is the only one left :)

I have setup a subdomain sub_example_com and two virtualhosts for it: one for port 80, second for 433. I've installed ssl wildecard (like this: http://phaseshiftllc.com/articles/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate.html) to use ssl on subdomains. It works, only issue is that I've a folder structure like /var/www/sub_example_com/

Then I've setup redirect from vhost:80 to vhost:433 using redirect (like this http://wiki.apache.org/httpd/RedirectSSL). So now, when someone uses only http it goes straight to https. Which is nice.

But. When someone enters example_com/sub_example_com/ it does not redirect him. I've tried setting up a ServerAlias but it didn't work. Also it seems a bit quirky to me.

How would you solve this problem? Is possible without using rewrite? Can it be done in definition?

Thanks in advance

PS. I've changed dots in address for dash because I can't post more than two link

1 Answer 1

2

You want to follow these instructions for rewriting HTTP to HTTPS:

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS

The RedirectSSL wiki page that you're using will only redirect a single URI, not all URIs on the non-SSL site.

So, something like this in the non-SSL virtual host:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

The above will redirect every request to the HTTP server over to the HTTPS server. The above link will also show you what to do if you only want to redirect specific directories.

As an aside, the ServerAlias directive is not for this. It's for matching alternative names when you're using Name VirtualHosts. You should revert it back to what you had before.

2
  • Thank you for the answer. I've changed a ServerAlias - I missunderstood that one :) As for .htaccess, on wiki they say that it is not a recommended solution (and they don't really show how to do this in a different way) so I've tried it - but got some internal errors and gave up. I've set SSLRequireSSL so that page is accessible only through subdomain. Thanks for your help! Aug 9, 2012 at 9:06
  • Well, SSLRequireSSL didn't work for me. When I set it on directory in my subdomain virtualhost it also catches /var/www/ and doesn't allow http there. Aug 9, 2012 at 10:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .