htaccess detect for SSL and reload with SSL

dev09
dev09 used Ask the Experts™
on
Hi guys,

I'm after some htaccess code that will

1. Detect to see if https is present in URL
2. If it is, then do nothing
3. If it is not, then reload the current page with https

Thanks in advance!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fixer of Problems
Most Valuable Expert 2014
Commented:
I believe this is the normal script.  It looks at the port instead of the URL and it uses the complete URL for some technical reason I can't remember at the moment.  The $1 is the current page in the original URL.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Open in new window


More versions here: http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html
Top Expert 2005

Commented:
Looking at the port is almost cases OK, however I would advise this improvement

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial