How to redirect the accesses in https by using the .htaccess ? Print

  • 0

Modify the .htaccess

We advise you to use cPanel to force the redirection of accesses in https /fr/base-de-connaissances/58/comment-rediriger-tous-les-acces-en-https.html . But it is also possible to do this by modifying the .htaccess.

To do this, you must modify the ".htaccess" file located at the root of your site by adding the following lines:

RewriteEngine On
RewriteRule "^.well-known/acme-challenge" - [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



If you don't know how to modify your ".htaccess" file, here are descriptions of several methods that will allow you to do so:

Method 1: FTP access

  1. Upload your ".htaccess" file via your FTP account;
  2. Modify the downloaded file with a suitable plain text editor to add the lines mentioned above;
  3. Save your modified file;
  4. Upload your new modified ".htaccess" file overwriting the old one to your account via your FTP access.

Method 2: control panel

  1. Connect to your control panel;
  2. In the"FILES" tab, click on"File Manager";
  3. At the top right of the File Manager, click on"Settings";
  4. In the window that appears, check the box"Show hidden files (dotfiles)" ;
  5. Confirm your settings by clicking on"Save";
  6. Navigate to the root folder of the site for which you want to force secure access (usually the"public_html" folder);
  7. Right click (or Ctrl+Click on MacOS) on the file named ".htaccess" that is there, and in the contextual menu that appears, select the"Edit" item;
  8. If necessary, validate the edition in the proposed format (usually"utf-8") and click on the"Edit" button;
  9. Modify the file by adding the lines mentioned above (it is possible that your ".htaccess" file is empty at the time of its first edition, do not worry, add the lines anyway);
  10. Click on"Save changes" ;
  11. You can now click"Close" to return to the File Manager. You can disable thedisplay of hidden files for a better browsing experience.

 


Was this answer helpful?

Back