0

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

  • 1
    Is your SSL certificate valid for `www.domain.tld`? (btw. please use `example.com` instead of `domain.tld`, which is a domain reserved for documentation purposes). If not, you will get such warnings. Further, I suggest to strip it down to a minimal example. – StephenKing Feb 15 '16 at 10:45
  • Thanks for your suggestions. I edited the post to only contain the relevant parts of the .htaccess file and I replaced the domain.tld by example.com. Also, the certificate is valid for example.com (not www.example.com), which is why any requests should be forwarded to https://example.com. – allyourbase Feb 16 '16 at 12:42
  • See here: http://stackoverflow.com/questions/4192948/remove-www-site-wide-force-https-on-certain-directories-and-http-on-the-rest – ESP32 Feb 17 '16 at 21:44
  • Did this ever get resolved? If yes, you could post an answer yourself (and mark it as accepted), as it might be helpful to others. That way, your question will no longer show in the unanswered list. – Sybille Peters Dec 14 '17 at 17:46

0 Answers0