Skip to content

The Geek Worker

Random Computer Issues And Things That Fixed Them For Me

  • About this Website
  • Helpful Links

Apache: How To Redirect http to https

April 17, 2014 by geekworker

If you want to direct traffic from your http so that it gets encrypted, this is really easy to do in Apache:

Step one: Set up your https vhost:

<IfModule mod_ssl.c>
<VirtualHost 10.1.1.1:443>
DocumentRoot /var/www
# other server options go here as needed
# – logging for example
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.cert
SSLCertificateKeyFile /etc/ssl/private/example.key
# Add other SSL specific options as needed</pre>
</VirtualHost>
</IfModule>

Step two: Set up your http vhost:

<VirtualHost 10.1.1.1:80>
ServerName my.example.com
RedirectPermanent / https://my.example.com/
</VirtualHost>

We have previously posted more information on enabling SSL in Apache.

Obviously, instead of 10.1.1.1 and my.example.com you’ll have to use your own IP and hostname, whatever they may be.

Note that this will redirect everything from http to https. Finer control is possible, for example you could do:

RedirectPermanent /secure/ https://my.example.com/secure/

Or you could use RewriteRules for even more control. However, in the age of mass surveillance and constant threats from hackers, a general redirect to https is a good idea.

Posted in ArticleTagged Apache, SSL
Previous story Could not perform immediate configuration on ‘python-minimal’ Next story Adding Blog as a Menu Item in WordPress

3 Comments

  1. passerby says:
    August 2, 2017 at 10:41 pm

    Just want to let the readers know that they must include the bracket angle and slash. WordPress is filtering html code so they must edit accordingly. Thanks

    Reply
  2. Nils says:
    August 2, 2017 at 10:41 pm

    Yup, myweb.com (without a preceding hostname) and http://www.myweb.com are unique and would require different certificates. myweb.com – without a prefix – would also not be covered by a *.myweb.com wildcard certificate, which is counter-intuitive to a lot of people. Thanks for your comment, passerby!

    Reply
  3. passerby says:
    August 2, 2017 at 10:41 pm

    Hi, I've had problem because I only bought cert for non www for example myweb.com so when client entered http://www.myweb.com will cause problem. They will not redirected to https://myweb.com. So here's the fix:

    NameVirtualHost *:80

    ServerName myweb.com
    ServerAlias http://www.myweb.com
    RedirectPermanent / https://myweb.com/

    Thought I could share here. Thanks again.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Inkscape: “Document Properties” Window Not Showing Up
  • Synology Drive Client does not connect on Apple MacOS
  • “The iTunes Store is temporarily unavailable. Please try again later” when trying to subscribe to Podcast
  • “Access Denied” Errors with TortoiseSVN on Samba
  • Keyboard and Mouse Microstutters with a Dell Latitude Notebook

Recent Comments

  1. Bart on Gigabyte OSD_Sidekick: “Please check if your USB cable is connected”
  2. Jason on Sony Vegas and Sony Movie Studio: No Audio Tracks In mp4 video filefound
  3. DaReclama on OpenVPN: IP packet with unknown IP version seen
  4. vilva on Excel Formula to get Number of Days in a Month
  5. Michael (Micky) Avidan on Excel Formula to get Number of Days in a Month

© 2026 The Geek Worker. Proudly powered by WordPress.