Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.
The following page has been changed by slive: http://wiki.apache.org/httpd/Recipes/RedirectSSL ------------------------------------------------------------------------------ = Redirect Request To SSL = Lets say you want 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 this way. - This is how to prevent it with mod_rewrite. + == Using mod_rewrite == {{{ <Location /secure> RewriteEngine On @@ -15, +15 @@ '''Note: It can also be use inside a directory or vhost container.''' - Make sure you have loaded mod_rewrite and have it enabled. + Make sure you have loaded [http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html mod_rewrite] and have it enabled. {{{ LoadModule rewrite_module modules/mod_rewrite.so RewriteEngine On }}} + == Using virtual hosts == + + When using SSL, you will frequently have at least two virtual-hosts: one on port 80 to server 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 [http://httpd.apache.org/docs/trunk/mod/mod_alias.html#redirect Redirect] directive inside the non-secure VirtualHost: + + {{{ + NameVirtualHost *:80 + <VirtualHost *:80> + ServerName mysite.example.com + DocumentRoot /usr/local/apache2/htdocs + Redirect permanent /secure https://mysite.example.com + </VirtualHost> + + <VirtualHost _default_:443> + ServerName mysite.example.com + DocumentRoot /usr/local/apache2/htdocs + SSLEngine On + # etc... + </VirtualHost> +
