Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to use an .htaccess file to use mod_rewrite to switch the protocol from http:// to https:// when someone hits my website.

For instance, once someone goes to: http://www.mywebsite.com/

I'd like the browser to switch to: https://www.mywebsite.com/

The same goes for the http://mywebsite.com/ -> https://mywebsite.com

This is the following code I've been using and I've experienced some odd things so if anyone could provide me with information if this is the right way to do it, or if you have a better way, please provide it. Thanks in advance.

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.ebaillv.com/$1 [R=301,L]
share|improve this question
up vote 2 down vote accepted

You could try checking for HTTPS instead of whether the port is 443. Also, the rule below matches everything and redirects it to exactly the same as it was but with the https. You could probably throw the [R=301, L] at the end of it if you wanted.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
share|improve this answer
Sorry for the delay. This looks like a great alternative. Thanks Bob! – Mike Jul 7 '11 at 2:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.