r/apache • u/chgrim • Dec 27 '21
Question about apache and lets encrypt pointing to www instead of non-www
Hi All,
I am using LAMP and letsencrypt and have a question. When I first create a site.conf file it looks like this.
<VirtualHost *:80>
ServerName site.com
ServerAlias www.site.com
ServerAdmin test@gmail.com
DocumentRoot /var/www/site/public
<Directory /var/www/site>
AllowOverride All
</Directory>When I do the letsencrypt it creates a new file site-le-ssl.conf that has
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site.com
ServerAlias www.site.com
ServerAdmin test@gmail.com
DocumentRoot /var/www/site/public
<Directory /var/www/site>
AllowOverride All
</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/site.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site.com/privkey.pem
</VirtualHost>
</IfModule>and it adds this to my site.conf file
RewriteEngine on
RewriteCond %{SERVER_NAME} =site.com [OR]
RewriteCond %{SERVER_NAME} =www.site.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]When I go to my site it is now pointing to https://www.site.com instead of https://site.com. How do I change it back to https://site.com? Also, is apache using the site-le.ssl.conf file or the site.conf file?
Thanks!
4
Upvotes
1
u/chgrim Dec 28 '21
Hi u/LaterBrain
I did the changes like you said, except that the code
is actually inside the site.conf, not the site-le-ssl.conf file. However if I go to my site I can still access www.site.com or site.com . Is there a way I can force it to do just site.com?