I'm having a weird problem with an htaccess (Apache version 2.4). I am using the folliwing code:
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
to force the following redirects:
- http should become https in general
- any www. should be removed
As it's a TYPO3 installation, I'm having a domain record inserted at the entry page, but it does not have any redirects whatsoever. So any redirecting is/should be done by the .htaccess file.
However, here is the problem:
- http + example.com gets forwarded to https + example.com
- https + example.com stays the same
- http + www + example.com gets forwarded to https + example.com
- https + www + example.com stays the same, instead of forwarding to http + example.com
Does anybody have any idea what could be wrong with the code in the .htaccess file? The problem is that if a user uses https://www.example.com/, he gets an annoying certificate issue warning. But as I understand the code, it should forward if either there is no https or if the domain is not "example.com", e.g. "www.example.com", so basically, it should work, no?
Thanks in advance, Thomas