Redirection of HTTP to HTTPS (80 - 443) is a nasty business and some of the items seen from the Internet would not really give you the exact procedure on how to do it. In this post I am going to give-away my "secret recipe" to totally do just that. So without further introduction lets go down the details:
Requirement is that you have your mod_rewrite module loaded by apache so I won't show you how to that here since its already elementary.
Look at this piece of code and its one of those tadah moments!
==========================================================
#########################################
#### XXX: BEGIN EDIT FOR MOD_REWRITE ####
#### This is intended to force HTTPS ####
#### for all inbound HTTP requests ####
####
# This module (mod_rewrite) simply tells Apache2 that all connections to
# port 80 need to go to port 443 – SSL – No exceptions
####
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine on
####
# The line below sets the rewrite condition for mod_rewrite.so.
# That is, if the server port does not equal 443, then this condition is true
####
ReWriteCond %{SERVER_PORT} !^443$
####
# The line below is the rule, it states that if above condition is true,
# and the request can be any url, then redirect everything to https:// plus
# the original url that was requested.
####
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
#### XXX: END EDIT FOR MOD_REWRITE ####
#######################################
No comments:
Post a Comment