简体   繁体   中英

Ways to redirect http:// to https://

We have a Drupal 8 application hosted on Ubuntu server with Apache, PHP 5.6 and MySQL 5.6. I want to know in howmany ways can we redirect domain from http:// to https:// protocol.

I have tried following ways

  1. From virtual host configuration file using redirect.
  2. Enabled rewrite rule and provided redirect condition in .htaccess file of the project.

When I use above approaches the site is getting down when number of requests increased. If I remove the redirect conditions the site is working fine even when more requests come to the server.

So, I want to know are there any other ways to redirect domain from http:// to https:// protocol without burden on the server.

  • Configure mod_rewrite in your httpd.conf to achieve such a redirect

For example:

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
<VirtualHost *:80>
  <IfModule mod_rewrite.c>
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
  </IfModule>
</VirtualHost>

or

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R]

or

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM