Solved Apache users (LAMP / WAMP) redirect traffic to https instead of http


jimbo45

Well-known member
Power User
VIP
Local time
10:23 AM
Posts
1,488
Location
Hafnarfjörður IS
OS
Windows XP,7,10,11 Linux Arch Linux
Hi folks
Messing around again with a local webserver -- learning as I go -- using Apache V2.4 as the web server.

I'm trying to redirect ALL traffic to https instead of http but I can't get it to work -- even with a "Virtual Server"

NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.example.com
Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

restarted the httpd server

Any help out there appreciated

I'm sure it must be similar in IIS if that's what people are using.

cheers
jimbo
 

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7

z3r010

Administrator
Staff member
Local time
11:23 AM
Posts
1,893
Location
Worsley, Manchester, UK
OS
Windows 11 Workstation
In .htaccess file in your site root folder

Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

More -
 

My Computers

System One System Two

  • OS
    Windows 11 Workstation
    Computer type
    PC/Desktop
    Manufacturer/Model
    doofenshmirtz evil incorporated
    CPU
    Ryzen 9 5950X
    Motherboard
    Asus ROG Crosshair VIII Formula
    Memory
    Corsair Vengeance RGB PRO Black 64GB (4x16GB) 3600MHz AMD Ryzen Tuned DDR4
    Graphics Card(s)
    ASUS AMD Radeon RX 6900 XT 16GB ROG Strix LC OC
    Sound Card
    Sound BlasterX Katana
    Monitor(s) Displays
    3 x27" Dell U2714H & 1 x 34" Dell
    Hard Drives
    Samsung 980 Pro 1TB M.2 2280 PCI-e 4.0 x4 NVMe Solid State
    Drive
    PSU
    ASUS ROG THOR 850W 80 Plus Platinum
    Case
    ASUS ROG Strix Helios Midi-Tower ARGB Gaming Case
    Cooling
    ASUS ROG Strix LC Performance RGB AIO CPU Liquid Cooler - 360mm
    Keyboard
    Logi Ergo
    Mouse
    Logitech MX Master 3
    Internet Speed
    900/100 Mbps
    Browser
    Chrome
    Antivirus
    Windows Defender, Malwarebytes Pro
    Other Info
    HP M281 Printer
    Logitech Brio Stream webcam
    Yeti X mic
  • Operating System
    Windows 10
    Computer type
    Laptop
    Manufacturer/Model
    Surface Laptop
    CPU
    i7

jimbo45

Well-known member
Power User
VIP
Thread Starter
Local time
10:23 AM
Posts
1,488
Location
Hafnarfjörður IS
OS
Windows XP,7,10,11 Linux Arch Linux
In .htaccess file in your site root folder

Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

More -
Thanks

You are a winner in this stuff == worked a treat. I'd forgotten about that .htaccess file. Had one but in the wrong folder. Now marking as solved.

Still learning --

cheers
jimbo
 

My Computer

System One

  • OS
    Windows XP,7,10,11 Linux Arch Linux
    Computer type
    PC/Desktop
    CPU
    2 X Intel i7
Top Bottom