Skip to content

Instantly share code, notes, and snippets.

@waifung0207
Last active September 28, 2022 03:22
Show Gist options
  • Save waifung0207/1a4bf1c396699b707ed5 to your computer and use it in GitHub Desktop.
Save waifung0207/1a4bf1c396699b707ed5 to your computer and use it in GitHub Desktop.
Apache Virtual Host Config with HTTPS redirect and URL rewrite
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
# force HTTPS
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin info@website.com
DocumentRoot /var/www/html/website
ErrorLog /var/log/website/error.log
CustomLog /var/log/website/access.log combined
# SSL config
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/wildcard.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/wildcard.example.com/privkey.pem
# Configuration for website with .htaccess support
<Directory /var/www/html/website/>
Options -Indexes
AllowOverride All
Require all granted
ServerSignature Off
</Directory>
</VirtualHost>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment