How to automatically redirect http to https in Apache
February 1, 2007
I will share 2 ways to achieve this:
- Using mod_rewrite. Add these directives to your configuration file:
- Using Redirect. Add these directives to your configuration file:
SSLRequireSSL
Redirect permanent /secure https://www.domain.com/secure
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]
References:
Joseph Scott’s Blog
KarKomaOnline
Entry Filed under: LAMP. .
4 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed
1.
Jenny Rurn | February 26, 2007 at 10:12 pm
Very nice thanks!
There is more examples at Apache SSL in htaccess examples in case different situation pops up!
2.
Anil Kumar | October 16, 2008 at 7:34 pm
I add this code in last of the htaccess file.URL chnage to https,but files are not opened.Please send reply as early as possible
3.
Rob | January 24, 2009 at 2:44 am
Cool, I was wondering about this. Thanks for posting.
4.
ColtonCat | July 6, 2009 at 4:35 pm
The second way (Redirect permanent) would be faster as mod_rewrite is not started and no regexes are checked?