The Apache Haus Forum

Forum Topics => Apache 2.4 => Topic started by: cearlp on September 17, 2022, 01:55:43 AM

Title: Redirect http to https
Post by: cearlp on September 17, 2022, 01:55:43 AM
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?
Title: Re: Redirect http to https
Post by: mario on September 17, 2022, 06:33:42 PM
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.
Title: Re: Redirect http to https
Post by: cearlp on September 18, 2022, 03:51:02 AM
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
Title: Re: Redirect http to https
Post by: mario on September 18, 2022, 01:39:56 PM
Yes mod_rewrite.

In a Windows installation

LoadModule rewrite_module modules/mod_rewrite.so
in a linux installation run a2enmod rewrite
Title: Re: Redirect http to https
Post by: cearlp on September 18, 2022, 04:36:35 PM
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.
Title: Re: Redirect http to https
Post by: mario on September 19, 2022, 10:06:57 AM
You may post your vhost(s) config. so we can take a look at it.