I want to install Drupal in https, but I failed.The page is trying to open resources (css, etc) in http. How to solve this ?
-
2That can happen because you entered the website when it was in http, and urls are stored in http so. Can you try clear caches and enter on the site in https first?– mistermoperSep 28, 2017 at 15:21
-
@OmarMohamadElHassanLopesin Yes, I've tried that. But unfortunately it didn't work– AdityaSep 28, 2017 at 15:36
2 Answers
In Drupal 7 you could set the $base_url='https://example.com';
in /sites/default/settings.php.
For Drupal 8 it looks like $base_url has been removed in favor of trusted domain patterns which are protocol agnostic. Using .htaccess rules seems to be the recommended approach.
In .htaccess below RewriteEngine on
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
That's from this page: https://www.drupal.org/https-information
You can call the CSS, javascript, and other files using '//' as a prefix to the source. This renders the files for both http and https depending on how the page was rendered.
<script src="//code.jquery.com/jquery-3.2.1.js"></script>