Redirect Request To SSL
Let's say you want [WWW]
http://www.domain.com/secure/ to always be sent over SSL (I presume here that both the normal and the SSL vhost have the same content). You could do this by linking to the correct page from within your HTML pages... but there will always be some user who will sneak by it that way.
Using mod_rewrite
Code:
<Location /secure>
RewriteEngine On
ReWriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}:443%{REQUEST_URI} [QSA,R=permanent,L]
</Location>
Note: This snippet can also be used inside a directory or vhost container.
Make sure you have loaded [WWW] mod_rewrite and have it enabled.
Code:
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
Using virtual hostsWhen using SSL, you will frequently have at least two virtual hosts: one on port 80 to serve ordinary requests, and one on port 443 to serve SSL. If you wish to redirect users from the non-secure site to the SSL site, you can use an ordinary [WWW] Redirect directive inside the non-secure VirtualHost:
Code:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
Redirect permanent /secure https://mysite.example.com/secure
</VirtualHost>
<VirtualHost _default_:443>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>