Redirecting to HTTPs from any request

August 23, 2014 3.2k views

You know when you type in digitalocean.com it automatically redirects to https://www.digitalocean.com? I want that for my site! I spent a lot of time generating (and regenerating secure certs...thanks openSSL!) and I would love to force https. The only thing is I am having redirect loops and am not sure what I am doing wrong :/

Here's my httpd.conf:
Redirect permanent / https://www.<MYDOMAINNAME>.com:443

and here's my .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTPHOST}%{REQUESTURI}

So right now if I type in rhosfelt.com it does the automatic redirection to https, but how do I get it to do this for every subsite (/blog, /test.html etc)?

If I try to go to any other page I am getting a "This page has too many redirects" error.. Your help will be appreciated! Thanks!!!

2 Answers

This one works for m. In my .htaccess:

RewriteEngine On
RewriteCond %{SERVERPORT} 80
RewriteRule ^(.*)$ https://%{HTTP

Of course, this is assuming your .htaccess is working

  • Hey Adam, thanks for the advice. It appears those lines do not work for me :( Did you do anything else to get .htaccess to work?

Yes, to get .htaccess to work you must:

set AllowOverride All in your website conf file (in /etc/apache2/sites-available/yoursite.conf) like this:

<Directory /var/www/yourwebsite>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
                Require all granted

Enable mod_rewrite: sudo a2enmod rewrite
Reload apache: sudo service apache2 reload

Then your .htaccess file should work.

Have another answer? Share your knowledge.