0

I'm having trouble with my apache config. Several sites are hosted on the server, each connected to a domain.

Here's an excerpt from the config:

<VirtualHost *:80>
        ServerName [name].com

        Redirect permanent / https://[name].com/
</VirtualHost>

<VirtualHost *:80>
        ServerName www.[name].ch
        ServerAlias [name].ch

        Redirect permanent / https://www.[name].ch/
</VirtualHost>

What's working:

  • http requests to [domain].com and [domain].ch are redirected to https
  • http to www.[domain].com is redirected to https://[domain].com
  • https://www.[name].ch if requested directly (so presumably no issue with ssl config)

What's not working:

  • http to www.[domain].ch is redirected to https://[domain].com instead of https://[domain].ch

Requests to www.[name].ch are being returned with a 301 to https://[name].com.

apache2ctl -S lists all specified virtual hosts as expected.

Any hints as to what might be wrong with the config? I also had a look at this post (apache rewrite rules, non-www, https), which unfortunately didn't solve this problem.

  • I'm not sure if it matters at all, but in my setups I'm don't specify "permanent", and I'm using quotes around the "/" and the target URL, that is: redirect "/" "https://domain.ch". – Ole Wolf Nov 23 '20 at 10:49
  • Note that permanent redirects are cached by most, if not all web browsers, and when you later change your configuration your browser may still use cached previous settings ... Test with a new anonymous window or from a command line with `curl -v http://example.com` after making changes in your config and restarting Apache – Bob Nov 23 '20 at 11:00
  • @HermanB: very good point indeed. An icognito tab actually just gave a completely different result*. I'll check that out. *to be precise: it gives me the apache default page, so there's definitely something wrong with the config. – thisaintme Nov 23 '20 at 14:03

0 Answers0