htaccess HTTPS / SSL Tips, Tricks, and Hacks
« Security with Apache htaccess TutorialApache Variable Fun in htaccess »
Apache has the best SSL/HTTPS support and can be controlled by the httpd.conf file or other HTTPD server configuration file. This htaccess tutorial has htaccess example code to make it easy to secure and use HTTPS and SSL with Apache.
« Security with Apache htaccess | .htaccess Tutorial Index | » Apache Variable fun (mod_env)
Fixes double-login problem and guarantees that htpasswd basic authorization can only be entered using HTTPS.
NOTE: You will only find this method on this site and it is the most secure way to do this.
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
NOTE:The HTTPS variable is always present,evenif mod_ssl isn’t loaded!
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule "^/normal/secure(/.*)" "https://%{HTTP_HOST}$1" [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule "^(/secure/.*)" "https://%{HTTP_HOST}$1" [R=301,L]
This lets you use hyperlinks like this
/doc.html:SSL -- > https://google.com/doc.html /doc.html:NOSSL --> http://google.com/doc.html
RewriteRule ^/(.*):SSL$ https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^/(.*):NOSSL$ http://%{SERVER_NAME}/$1 [R,L]
MORE: Apache SSL in htaccess examples and https/ssl forum
« Security with Apache htaccess | .htaccess Tutorial Index | » Apache Variable fun (mod_env)
« Security with Apache htaccess Tutorial
Apache Variable Fun in htaccess »
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | .:: Phrack Magazine ::.
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd
thank you! The amount of times I’ve looked up .htaccess issues in Google and your site has come up with the answer – life saver.