1

I am forcing my webserver to rewrite a none www URL to www, e.g. https://example.com to https://www.example.com, via .htaccess.

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But my site does not load with www and prints ERR_TOO_MANY_REDIRECTS.

If I enter a URL like https://www.example.com/some-uri then I get redirected to https://example.com

DNS Zone Records DNS Zone Record

What might be the cause?

MrWhite
  • 11,643
  • 4
  • 25
  • 40
Black
  • 419
  • 6
  • 18
  • 1
    I was able to solve the problem. It was a magento setting. [More infos](https://magento.stackexchange.com/a/1338/66769) – Black Dec 12 '18 at 11:28
  • _Aside:_ Any reason why you are not redirecting to HTTPS with your `.htaccess` redirect? – MrWhite Dec 12 '18 at 11:30
  • @MrWhite, no, It is just dev .htaccess. I think I could just use `RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]` instead of `RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]` – Black Dec 12 '18 at 11:32
  • 1
    Write a proper answer. – Sven Dec 12 '18 at 11:35
  • Yes, if your site is HTTPS then you should simply redirect to `https://...`. The directive as it stands would keep the user on HTTP - if that was requested. Unless you have something before that redirects to HTTPS? (And/or possibly result in a 2nd redirect to HTTPS later?) – MrWhite Dec 12 '18 at 11:36
  • @Sven, I wrote a proper answer, but it was moved to the comment section. – Black Dec 12 '18 at 11:42
  • I don't see an answer converted to a comment. Also: An answer should never consist of a link only to prevent link rot (even within the SE network). – Sven Dec 12 '18 at 11:45

1 Answers1

3

I was able to solve the problem. It was a magento setting.

There is a setting in system->configuration->Web->Url Options->Auto-redirect to Base URL. Set that to 'No'.

Black
  • 419
  • 6
  • 18
  • I can accept this answer in 2 days. – Black Dec 12 '18 at 15:23
  • 1
    If that solved the problem, then the base URL is almost certainly wrong. Check it and fix it. – Michael Hampton Dec 12 '18 at 17:27
  • Thanks for the hint @MichaelHampton. You are right, I also had to change the Base URL in the backend (for secure and unsecure) from `https://mycompany.de/` to `https://www.mycompany.de/` – Black Dec 13 '18 at 08:28