Redirecting to HTTPs from any request

Posted August 23, 2014 6.5k views

You know when you type in it automatically redirects to 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 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!!!

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.

Submit an Answer
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

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.