Ssl – Best practices for keeping a portion of website under https & under http for the rest

httphttpsssl

I have certain portion of my site to be behind SSL which is reserved for registered users & want rest of the site which is open to public to be served by just http. Currently it is set up so that all the pages be it public or otherwise are served by https. Also botht he public & non-public content resides under the same webroot.

Can you guys suggest me a way to resolve this so or perhaps a best practice guide?
Thanks!

EDIT

We use LAMP stack.

Best Answer

This pseudo-conf for Apache will do what you require: two virtual hosts, one with SSL, and redirects from the SSL-required path(s) to the HTTPS version of the site.

<VirtualHost *:80>
ServerName www.sample.com
DocumentRoot /var/www/www.sample.com

Redirect permanent /secure https://www.sample.com/secure
Redirect permanent /secure2 https://www.sample.com/secure2
</VirtualHost>

<VirtualHost *:443>
Servername www.sample.com
DocumentRoot /var/www/www.sample.com

SSLEngine On
</VirtualHost>

Once you've given your users a cookie keying to their identity, it's best to keep them on the SSL version of the site, so that their cookie can't be hijacked by malicious users on their unencrypted coffeeshop wireless connection, for example. You have a couple of options for making that work. Either use your application language (eg PHP) to detect the cookie and then redirect to the SSL version of the current page, or you could use mod_rewrite to force SSL when the cookie exists. But that's another question...