Skip to content

Instantly share code, notes, and snippets.

@masiur
Last active June 8, 2020 08:41
Show Gist options
  • Save masiur/7e5d610669692b72caa98652c8bbc21b to your computer and use it in GitHub Desktop.
Save masiur/7e5d610669692b72caa98652c8bbc21b to your computer and use it in GitHub Desktop.
apache redirectin www/non-www to www with https

Written with StackEdit.

/etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    RedirectMatch permanent ^/(.*) https://www.example.com/$1
</VirtualHost>

/etc/apache2/sites-available/example.com-le-ssl.conf

<IfModule mod_ssl.c>
 <VirtualHost *:443>
   ServerName example.com
   RedirectMatch permanent ^/(.*) https://www.example.com/$1

 </VirtualHost>
</IfModule>


<IfModule mod_ssl.c>
 <VirtualHost *:443>
  ServerAdmin yourmail@example.com
  ServerName www.example.com
  DocumentRoot /var/www/html/
  <Directory "/var/www/html/">
  AllowOverride All
  </Directory>

  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
 </VirtualHost>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment