Question

Redirect from http://sub.site.com to https://sub.site.com is instead going to http://www.sub.site.com

I am using LetsEncrypt to add SSL certs to all my domains. I used the “force redirect to https” option when I set up the cert, which added the redirect to my *:80 virtualhost and created a *:443 virtualhost with the correct config. However, it’s behaving really strangely.

If you go to http://blog.ryangiglio.com, it 301 redirects you to http://www.blog.ryangiglio.com. Nowhere in my config do I see a reason for that to happen, and I can’t figure out how to view the level of logs that would help me debug the issue.

Here are my conf files:

blog.ryangiglio.com.conf

<VirtualHost *:80>
    ServerName blog.ryangiglio.com

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =blog.ryangiglio.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

blog.ryangiglio.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
	ServerAdmin webmaster@localhost
	ServerName blog.ryangiglio.com

	DocumentRoot /var/www/blog.ryangiglio.com/public_html
	ErrorLog /var/www/blog.ryangiglio.com/error.log
	CustomLog /var/www/blog.ryangiglio.com/access.log combined

  <Directory /var/www/blog.ryangiglio.com/public_html/>
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
SSLCertificateFile /etc/letsencrypt/live/blog.ryangiglio.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.ryangiglio.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
</IfModule>

Any help would be appreciated. Thanks!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@ryangiglio

I’m seeing something entirely different on my end, though neither redirect to anything when I access them.

When I visit https://blog.ryangiglio.com/, I see one site with two posts. It doesn’t redirect to www.

When I visit http://www.blog.ryangiglio.com/, I see an entirely different website.

When checking the IP they resolve to, they both resolve to the same IP address, so the issue here is configuration. Are there any other configuration files that you can provide? Something is separating the two and pointing to two entirely different directories from what I’m seeing on my end.

Hi @ryangiglio Looking at those two configurations, should never result in 301 to www.sub.site.com Are you sure there might not be hiding a configuration somewhere else? Or maybe your .htaccess has some redirects? Try running this to list all the VirtualHosts: sudo apache2ctl -S