You may want to redirect all traffic from http://example.com and http://www.example.com to https://example.com. You can do this by adding the code below to your server configuration file, i.e., the VirtualHost definitions:
VirtualHost *:80> ServerName www.example.com Redirect "/" "https://www.example.com/" </VirtualHost> <VirtualHost *:443> ServerName www.example.com # ... SSL configuration goes here </VirtualHost>
The use of RewriteRule would be appropriate if you don’t have access to the main server configuration file, and are obliged to perform this task in a .htaccess file instead:
RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www.example.com* RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
There are existing comments in .htaccess that explain how to redirect http://example.com to http://www.example.com (and vice versa), but this code here redirects both of those to https://example.com.
Similar Posts:
- how to redirect to https in drupal 8 / 9
- how to redirect html site to https using htaccess
- How to prepare module skeleton for Drupal 8
- Install Drupal 8 via composer
- How to change Drupal core files
857