Aller au contenu principal

Drupal 10, rediriger les requêtes http vers https

La redirection des requêtes non sécurisé (http) vers https peut se faire de differente facon. Nous vous proposons une approche simple via le fichier .htaccess

Vous devez ajouter le code suivant dans le fichier .htaccess
 

   # NEW CODE HERE #
   RewriteCond %{HTTPS} off
   RewriteCond %{HTTP:X-Forwarded-Proto} !https
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # END NEW CODE #
Votre fichier devrait ressembler à :
...
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  
   # NEW CODE HERE #
   RewriteCond %{HTTPS} off
   RewriteCond %{HTTP:X-Forwarded-Proto} !https
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # END NEW CODE #

  # Set "protossl" to "s" if we were accessed via https://.  This is used later
  # if you enable "www." stripping or enforcement, in order to ensure that
  # you don't bounce between http and https.
  RewriteRule ^ - [E=protossl]
  RewriteCond %{HTTPS} on
  RewriteRule ^ - [E=protossl:s]

  # Make sure Authorization HTTP header is available to PHP
  # even when running as CGI or FastCGI.
  RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
...
 

Redirection vers un domaine en utilisant le fichier .htaccess

Afin d'eviter la double indexation, il est important de rediriger toutes les requetes soit sur www.monsite.com ou monsite.com.
Pour habeuk, nous avons opter d'utiliser habeuk.com laugh.
 
  ##### NEW CODE HERE
  # Redirection www vers non-www
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^www\.monsite\.com [NC]
  RewriteRule ^(.*)$ http://monsite.com/$1 [L,R=301]

  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP_HOST} ^www\.monsite\.com [NC]
  RewriteRule ^(.*)$ https://monsite.com/$1 [L,R=301]


 
Profile picture for user admin Stephane K

Écrit le

Il y'a 11 mois
Modifié
Il y'a 1 mois
Loading ...
WhatsApp
Support Habeuk : +237 694 900 622
WhatsApp Send