Question

VirtualHost https redirect issue

I was following the guide on https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority and it works up to the point where I can get SSL working if I actively go to https, but anyone who goes to http is stuck there.

I’ve tried:

redirect rules RedirectMatch permanent /(.*) https://www.example.com/$1 Adding those same things to 443

I’ve checked other threads like https://webmasters.stackexchange.com/questions/28875/redirect-permanent-and-https and I think I’m officially out of answers.

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

<VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com turnovers.example.com www.turnovers.example.com example.com.kjr.local

        DocumentRoot /var/www/sales/sales-git
        CustomLog /var/www/sales/logs/access_log combined
        ErrorLog /var/www/sales/logs/error.log

        SSLEngine On
        SSLCertificateFile /home/user/example.com.crt
        SSLcertificateKeyFile /home/user/example.com.key
        SSLCertificateChainFile /home/user/intermediate.crt

        <Directory "/var/www/sales/sales-git/">
                Options -Indexes +FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        SetEnvIfNoCase Host ^turnovers.example.com$ ok
        SetEnvIfNoCase Host ^example.com$ ok
        SetEnvIfNoCase Host ^www.example.com$ ok

        <Location />
                Order Deny,Allow
                Deny from all
                Allow from env=ok
        </Location>
</VirtualHost>

Any help is welcome!!!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Turns out that there was an .htaccess I couldn’t see mucking everything up. Applied a forwarding rule there and it worked out just fine.

Can you try adding the line return 301 https://$host$request_uri; to your VirtualHost and remove all the other HTTPS redirect information?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.