I got the basic Apache configuration more or less figured out with the guidance of the Apache manual but the redirection rules are a bit to complicated for me at this time so I hope you can help me.
I want to achieve the following:
- Every incoming request over http should be redirected to use https.
- Every subnet except for the ones defined as a vhost (m.domain.tld and content.domain.tld) should redirect to domain.tld.
- I rather keep everything after the “/” but this isn’t necessary.
For example:
- http:/domain.tld → https:/domain.tld
- http:/whatever.domain.tld → https:/domain.tld
- https:/whatever.domain.tld → https:/domain.tld
- http:/m.domain.tld → https:/m.domain.tld
I got the basics working with this very basic rule but it only works for request coming in over http so non-existing subnets coming in over https aren’t reformatted.
<VirtualHost _default_:80>
Redirect permanent / https://domain.tld/
</VirtualHost>
Hope you can help or point me in the direction of a clear guide (haven’t fount one yet).
Try these mod_rewrite rules:
Keep in mind, that in order to be able to server something.example.com you need proper SSL certificate for that particular subdomain or wildcard SSL certificate that will cover ANY subdomain. It is important, as SSL part of HTTPS works way before mod_rewrite will have a chance to do anything (it only kicks in when secure connection is already properly established).