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


jimbo45

Well-known member
Pro User
VIP
Local time
10:03 PM
Posts
4,705
Location
Hafnarfjörður IS
Visit site
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
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 U2724D & 1 x 34" Dell U3415W
    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 Vertical
    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
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
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
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
Hello,
I am using wamp server in windows. I have successfully installed SSL certs. Now https is working without any issue.
But http redirection is not working.

<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
Redirect permanent / https://test.com/

</VirtualHost>

<VirtualHost *:443>
ServerName test.com
ServerAlias www.test.com
DocumentRoot "C:/wamp64/www/test"
<Directory "C:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile "C:/wamp64/bin/apache/apache2.4.41/conf/key/fullchain.pem"
SSLCertificateKeyFile "C:/wamp64/bin/apache/apache2.4.41/conf/key/privkey.pem"
SSLCertificateChainFile "C:/wamp64/bin/apache/apache2.4.41/conf/key/fullchain.pem"
</VirtualHost>

Could you please help me figure out this one?
 

My Computer

System One

  • OS
    Windows

Latest Support Threads

Back
Top Bottom