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

Related Questions

KernelEvents::REQUEST is not fired on cached pages

2  Asked on December 8, 2021 by user34185

     

Add column to custom field schema

3  Asked on December 8, 2021 by coder1

 

Order receipt email content

1  Asked on December 8, 2021 by pete-l

 

Date time save in database

0  Asked on December 8, 2021 by pratip-ghosh

   

How can I create a recommended project in the root directory?

2  Asked on December 6, 2021 by user2574948

   

Wrapping fields together in a Views Exposed Filter

1  Asked on December 4, 2021 by typologist

   

Submit form and disable submission button

7  Asked on December 4, 2021 by matt9292

   

How to check if an entity is referenced before deleting?

2  Asked on December 2, 2021 by halofx

   

Add class to {{ link }} twig attribute

3  Asked on December 2, 2021

   

Remove field attributes using hook_form_alter()

1  Asked on November 30, 2021 by senthilkumar

 

How to send email to submitter in a webform?

2  Asked on November 30, 2021 by cel57

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP