With Apache’s VirtualDocumentRoot directive, it’s very easy to have both http and https servers listening on the same hostname. Of course, this means that a user can request the https version of the page unencrypted, which may not be desired.
For example, say we have an application with its main web page at http://example.com. There is also an administrative backend, https://secure.example.com. The web server and DNS are set up such that these are listening on the same IP, with the same basic document structure:
example.com/_ -> www
example.com/secure
example.com/www
This means that the web server will answer requests to http://secure.example.com (and https://example.com, but that’s not as terrible). To fix this, we can throw a .htaccess file into the secure subdomains document root that enforces TLS:
RewriteCond %{HTTP_HOST} ^secure.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
Now calls to (only) http://secure.example.com redirect properly to the TLS-secured admin interface. Moreover, you can throw this into the main apache config to have it apply to all vhosts; as long as they start with secure., they’ll force the user to use TLS.