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 pctony:
http://wiki.apache.org/httpd/Rewrite/Common/http2https

The comment on the change is:
Added new page. For review. Content copied from Richs' wiki, in essence at least

New page:
== HTTP to HTTPS ==

=== Scenario : ===
You want to force people coming to your site to use HTTPS.  Either for the 
entire site or a small sub-section of it.

=== Fix : ===

'''Entire site (httpd.conf) :'''
{{{
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This basically checks to make sure the connection is not already HTTPS

RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same 
location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
}}}
 

'''Entire site (.htaccess) :'''

''Note:  You will need to ensure that you place this in a .htaccess file in the 
root of the site you want to apply it against, and to make sure you have the 
appropriate !AllowOverride configuration in your httpd.conf''
{{{
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same 
location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
}}}


'''Specific Directory (httpd.conf)'''

''Note:  This will need to be added to an appropriate <Directory> block.''
{{{
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This basically checks to make sure the connection is not already HTTPS

RewriteRule ^/secure(.*) https://%{SERVER_NAME}/secure$1 [R,L]
# This rule will redirect all users who are using any part of /secure/ to the 
same location but using HTTPS.
# i.e.  http://www.example.com/secure/ to https://www.example.com/secure/
# This means if you dont want to force HTTPS for all directories you can force 
it for a specific sub-section of the site.
}}}


'''Specific Directory (.htaccess)'''

''Note:  This htaccess file will need to be saved in the appropriate directory. 
 Again you need to make sure that you have the correct !AllowOverride settings 
in place''
{{{
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This basically checks to make sure the connection is not already HTTPS

RewriteRule ^secure(.*) https://%{SERVER_NAME}/secure$1 [R,L]
# This rule will redirect all users who are using any part of /secure/ to the 
same location but using HTTPS.
# i.e.  http://www.example.com/secure/ to https://www.example.com/secure/
}}}

Reply via email to