.htaccess tutorial

htaccess Elite


Redirecting All or Part of a Server to SSL

SSL, TLS related

Redirecting All or Part of a Server to SSL

Postby produke » 24 Oct 2006 23:34

Redirect non-https requests to https server fixing double-login problem and ensuring that htpasswd authorization can only be entered using HTTPS:
Code: Select all
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "google.com"
ErrorDocument 403 https://google.com


NOTE: This code fixes the issue of having to type in the username and password twice. (more info about this)

This will check to make sure that the connection IS using SSL, or it will fail.
It will also check to make sure that the HOST is tirmassagestone.com or it will fail
If it fails, it will issue a 403 "Forbidden" which will redirect to https://google.com


NOTE:There is a more thorough article at [url=http://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples.html]AskApache.com
[/url]

Redirect everything attached to port 80:
Code: Select all
RewriteCond "%{SERVER_PORT}"       "^80$"
RewriteRule "^(.*)$"               "https://%{SERVER_NAME}$1" [R=301,L]






Redirect particular URLs to a secure version:
Code: Select all
RewriteRule "^/normal/secure(/.*)" "https://%{HTTP_HOST}$1" [R=301,L]






Check to see whether the HTTPS environment variable is set:
Code: Select all
RewriteCond %{HTTPS} !=on
RewriteRule "^(/secure/.*)" "https://%{HTTP_HOST}$1" [R=301,L]






Use the Redirect directive to cause a URL to be served as HTTPS:
Code: Select all
Redirect / https://google.com/






Changing the scheme (SSL/noSSL) using relative URLs:
Code: Select all
RewriteEngine on
RewriteRule   ^/(.*):SSL$   https://%{SERVER_NAME}/$1 [R,L]
RewriteRule   ^/(.*):NOSSL$ http://%{SERVER_NAME}/$1  [R,L]


This lets you use hyperlinks of the form document.html:SSL
Last edited by produke on 21 Nov 2006 11:04, edited 2 times in total.
User avatar
produke
 
Posts: 242
Joined: 25 Sep 2006 04:48


Postby snooze » 26 Feb 2007 14:55

snooze
 
Posts: 26
Joined: 01 Nov 2006 05:19


Return to SSL