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.

  • 2
    the file name should be .htaccess not htaccess.php. This file should be present on the base directory of your drupal where index.php exists. ( This only applies for Apache webserver ) and also make sure the mod_rewrite is enabled on your server ( service restart required ).
    – shrish
    Commented May 24, 2016 at 4:50

3 Answers 3


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.

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.
  • 1
    Thank you! I think this would have worked, but I went with the module since it seemed more likely to be idiot proof :)
    – naomisl
    Commented May 24, 2016 at 21:22

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.