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 kinda new to this so bear with me. I just finished setting up SSL on my website. The problem is that if the user types www.mydomain.com into their browser, it doesn't connect securely with HTTPS.

However, if I type https://www.mydomain.com then it works just fine, and continues to work on subsequent pages, so I know SSL is working. My question is: how would I set the website so that users connect using SSL by default?

My first thought was to just redirect to the HTTPS version of the page, but that would mean I would have to put a redirect on every page in case the user doesn't come in via the landing page.

share|improve this question
up vote 3 down vote accepted

Assuming you are using Apache, you can place the following snippet in the .htaccess file in your root directory:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
share|improve this answer

If you have access to the Virtual Hosts settings at the httpd.conf level, another option using mod_alias would be:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost >

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost >
share|improve this answer

If you are using a programming language like PHP (or need another good reason to do so) and including a file at the beginning of every page, you can do a universal redirect easily enough with a few lines of code, such as:

if($_SERVER['SERVER_PORT'] != 443)
    header('Location: https://www.example.com'.$_SERVER['REQUEST_URI']);
share|improve this answer

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.