Question

Redirecting to HTTPs from any request

  • Posted on August 23, 2014
  • rhosfeltAsked by rhosfelt

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://%{HTTP_HOST}%{REQUEST_URI}

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!!!


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.

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
	</Directory>

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

Then your .htaccess file should work.

This one works for m. In my .htaccess:

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Of course, this is assuming your .htaccess is working