Mobile app version of vmapp.org
Login or Join
Karen161

: Website doesn't default to HTTPS 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,

@Karen161

Posted in: #301Redirect #Https

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 mydomain.com into their browser, it doesn't connect securely with HTTPS.

However, if I type 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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Karen161

3 Comments

Sorted by latest first Latest Oldest Best

 

@Shakeerah822

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: www.example.com'.$_SERVER['REQUEST_URI']); exit;
}

10% popularity Vote Up Vote Down


 

@Alves908

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

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

<VirtualHost *:443>
ServerName example.com # ... SSL configuration goes here
</VirtualHost >

10% popularity Vote Up Vote Down


 

@Kevin317

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 ^(.*)$ example.com/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme