Apache, non-WWW to WWW (HTTPS/Secure)
Thursday, 30 September 2021
Here is my “normal” config file and just “gets the task done”.
Here’s my Updated File
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@domain.co.uk
ServerName www.domain.co.uk
ServerAlias domain.co.uk
DocumentRoot /var/www/html/domain
<Directory /var/www/html/domain/>
Options FollowSymLinks
AllowOverride All
Require all granted
# Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.co.uk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.co.uk/privkey.pem
</VirtualHost>
</IfModule>
Where I have got the “Redirect non-www to www are the few lines where I have tried to make the changes done.
- Published in Apache, PHP Programming, Server, Ubuntu
No Comments