Redirect http to https

Started by cearlp, September 17, 2022, 01:55:43 AM

Previous topic - Next topic

cearlp

I have ServerName mysite.com
       ServerAlias www.mysite.com
       Redirect permanent / https://mysite.com
in the VirtualHost *:80 portion of my configuration file.
ServerName and ServerAlias are also in the VirtualHost *:443 portion.
Everything (mysite.com, www.mysite.com, https://myssite.com) gets directed to https except for when http://mysite.com is used as the URL.
Is there something I missed?

mario

in your port 80 vhost you can use mod_rewrite to force that

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Don't forget to restart apache.

cearlp

Mario, tried your suggestion, but restart of apache2 fails with error on the RewriteEngine line - Invalid Command perhaps misspelled ordained by a module not inc

mario

Yes mod_rewrite.

In a Windows installation

LoadModule rewrite_module modules/mod_rewrite.so
in a linux installation run a2enmod rewrite

cearlp

Okay, something is wrong with my setup. Safari works with everything except www.site. Firefox works only with https://. http://site and site alone is listed as Unsecure. www.site give a network protocol violation that cannot be repaired. An error in data transmission was detected.
Everybody that the site is designed for is instructed to just key in the site name alone, so I will just forget the Unsecure designation.

mario

You may post your vhost(s) config. so we can take a look at it.