htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Redirect Request To SSL - httpd.conf
PostPosted: 08 Nov 2006 22:29 
Offline

Joined: 30 Oct 2006 19:55
Posts: 99
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 hosts

When 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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB