7.4. Serving a Portion of Your Site via SSL
Problem
You want to have a certain portion of your site available via SSL exclusively.
Solution
This is done by making changes to your httpd.conf file.
For Apache 1.3, add a line such as the following:
Redirect/secure/https://secure.example.com/secure/
For Apache 2.0:
<Directory /www/secure>
SSLRequireSSL
</Directory>Note that the SSLRequireSSL directive does not issue a redirect. It merely forbids non-SSL requests.
Or for any version of Apache you can accomplish this using mod_rewrite:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]Discussion
It is perhaps best to think of your site’s normal pages and its SSL-protected pages as being handled by two separate virtual hosts rather than one. Although they may point to the same content, they run on different ports, are configured differently, and, most important, the browser considers them to be completely separate servers. So you should, too.
Don’t think of enabling SSL for a particular directory; rather, you should think of it as redirecting requests for one server to another.
Note that the Redirect directive preserves path information, which means that if a request is made for /secure/something.html, then the redirect will be to https://secure.example.com/secure/something.html.
Be careful where you put this directive. Make sure that you only put it in the HTTP (non-SSL) virtual host declaration. Putting it in the global section of the config file may cause ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access