Skip to content

Instantly share code, notes, and snippets.

@reddyweb
Last active April 7, 2019 12:42
Show Gist options
  • Select an option

  • Save reddyweb/ab91bf92c2a110454342307c255183aa to your computer and use it in GitHub Desktop.

Select an option

Save reddyweb/ab91bf92c2a110454342307c255183aa to your computer and use it in GitHub Desktop.
Enforce redirection to HTTPS

Redirect all traffic from http:// to https://

  • Below both are working fine, so choose any 1 option.

Option 1:

  • In .htaccess file, add below lines right after "RewriteEngine on"
  # Force redirect to HTTPS
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Option 2:

  • In virutal host, default configuration file add below line and restart apache server.
  # In /etc/apache2/sites-available/000-default.conf
  
  <VirtualHost *:80>
   ....
   ....
    
   Redirect permanent "/" "https://[YOUR IP ADDRESS OR DOMAIN NAME]/"
   ...
   
</VirtualHost>  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment