Skip to main content

Force HTTPS on ALL pages

Force HTTPS on ALL pages

There are various server setups and variations so there will not be one solution that fits all cases... However, this worked for me.

Put this in the .htaccess file just before RewriteCond %{REQUEST_FILENAME} !-f about line 117...

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Then in the settings.php add at the bottom...

$_SERVER['HTTPS'] = 'On';

Flush the cache and test!

For more information try https://www.drupal.org/https-information.

Update

The above worked really well on a dedicated server I had with Heart Internet. However, when I tried the same on a site that was on shared hosting with Heart Internet (via the Reseller package), I'd just get a nasty server error page. After a little digging within the Heart Internet customer support database I found a slight variation to the above code....

RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The only variation is the condition... RewriteCond %{HTTPS} off works in one environment, but bombs out in the other, and RewriteCond %{ENV:HTTPS} !=on works in the other.

Not being much of a server expert I can't explain the fine differences, but it looks like it's to do with the way it's checking if the site is running with SSL.

If you try both and still don't have any joy, but find another solution, drop me a line.

Main Category
  • Drupal 7
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • CodeIgniter
    • Handy Functions
    • MySQL
  • WordPress
  • About

BBC Technology News

  • Heathrow: Man charged with flying drone near airport
  • Girl Scouts of America offer badge in cybersecurity
  • Rise in nude photos sent to phones on public transport
  • Are these the faces of the future?
  • Zimbabwe blocks Facebook, WhatsApp and Twitter amid crackdown
More

Sitepoint

  • How to Build Your First Static Site with Gatsby
  • Customer Journey Maps: A Day in the Life of a Customer
  • How to Take JavaScript Beyond the Web in 2019
  • Check out the 6 Best Productivity Apps for Designers
  • 7 Awesome Wireframing Tools You Should Be Using
More

Heart Internet

  • Did he really just say that? How to deal with an obnoxious client
  • Product management for designers
  • Talking to your clients about WordPress plugin security
  • The developer’s guide to native web animation
  • Are you seeing clearly? The role of visual thinking in creative work
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
 

© Jon Moore 2019

All stock images are from www.istockphoto.com