TransWikia.com

redirect whole site to HTTPS

Drupal Answers Asked by naomisl on August 11, 2020

When I include the snippet found in answer to this question How to simply make the whole site HTTPS? to redirect to https in my htaccess.php file, all urls resove to /index instead of going to the page originally requested (Ex: user tries to access example.com/about, and is redirected to https://example.com).

Here is the snippet I used:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I have also tried the slight variation found at https://www.drupal.org/https-information, which has the same unsatisfactory result:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.domainname.com*
RewriteRule ^(.*)$ https://domainname.com/$1 [L,R=301]

How can I make the site all https without breaking the ability to navigate to a specific page?

Edited to add: I’ve got the Secure Pages module, but haven’t managed to get it to work. If you have advice on that point instead I’d happily take it.

3 Answers

You might be interested in the htaccess module:

Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings.

Drupal tries to provide a one size fits all htaccess for Apache webservers, but this goal is increasingly difficult. This module allows the webmaster to set specific options.

Also, this module is dedicated to webmasters who don't want to manually modify htaccess every time during a version upgrade to use Drupal.

It offers enabling HTTPS and then generates the .htaccess file for you.

Correct answer by Neograph734 on August 11, 2020

The example from @rjkunde didn't work on my local Lando based drupal development environment, the browser gave me the error message: "The page isn’t redirecting properly". The drupal documentation on Enabling HTTP Secure (HTTPS) helped me to solve the problem by adding a second rewrite condition RewriteCond %{HTTP:X-Forwarded-Proto} !https:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Answered by LarS on August 11, 2020

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.

Answered by rjkunde on August 11, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP