htaccess detect for SSL and reload with SSL

dev09 used Ask the Experts™
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!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fixer of Problems
Most Valuable Expert 2014
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 ^(.*)$$1 [R,L]

Open in new window

More versions here:
Top Expert 2005

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