Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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.

share|improve this answer
    
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! –  ziner Aug 9 '12 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. –  ziner Aug 9 '12 at 10:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.