-1

I added to the .htaccess file this code https://stackoverflow.com/a/13997498/2311074 to redirect my website always to https://www.**********. This works in Chrome, but it is not working in Firefox.

If I enter

https://example.com

then its not redirecting anywhere.

in Firefox. In Chrome they are correctly redirected to https://www.example.com.

I aready deleted the cache and tried to call the website from other PC's but its still not working. This is my htaccess FIle from Laravel:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On


    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

What am I doing wrong?

Adam
  • 15,564
  • 13
  • 95
  • 165
  • Have you tried it in Firefox's private mode? – Karolis Feb 17 '18 at 16:11
  • @Karolis yes in private mode and on other pcs (windows 7 and ubuntu). The redirect is still happening, the url is coaching-institutes.net – Adam Feb 17 '18 at 16:13

2 Answers2

0

The problem was that I only had a SSL certificate for the domain www.example.org but not a SSL certificate for the domain example.org. Thus the url https://example.org is invalid, was not loaded and could not be redirected with the .htaccess file.

Adam
  • 15,564
  • 13
  • 95
  • 165
-2

See comments below for the answer to question.

  • So you are saying that https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www/13997498#13997498 does not work in firefox? – Adam Feb 17 '18 at 16:09
  • Make sure you have the SSL installed for not just https but also www as well. – user9373919 Feb 17 '18 at 16:14
  • http://prntscr.com/ig267b Domain working for me in firefox, you must have incorrectly installed cert for https – user9373919 Feb 17 '18 at 16:16
  • I only have the SSL installed for `https://www.***` this is why I wanted the redirect to the www page in the first place – Adam Feb 17 '18 at 16:17
  • is the domain working for you if you enter `https://coaching-institutes.net` in your browser? I tried it also on other PC's and it was not working – Adam Feb 17 '18 at 16:18
  • Your website is configured incorrectly. I would suggest reinstalling your SSL cert for that domain. coaching-institutes.net uses an invalid security certificate. The certificate is only valid for the following names: www.nlp-institutes.net, www.coaching-institutes.net, www.world-hypnosis.org – user9373919 Feb 17 '18 at 16:20
  • SSL certificate is only setup for `www.coaching-institutes.net` and not for `coaching-instiutes.net`. Thats why I want a redirect to a `www.***` and I don't understand why its not working. – Adam Feb 17 '18 at 16:22
  • You do realize if you go to just `coaching-institutes.net` it redirects to the `https://` hence why i said install a cert for normal https and not just `www` and then you can implement a redirect from `https` to `https://www.` – user9373919 Feb 17 '18 at 16:25
  • `www.coaching-institutes.net` is working but `https://coaching-institutes.net/` is not working – Adam Feb 17 '18 at 16:27
  • Read my previous comments lmao. I have stated it several times now. – user9373919 Feb 17 '18 at 16:27
  • @Adam Having a www-only certificate, I would try swapping places of redirect rules, i.e. first redirect to www and then to https. – Karolis Feb 17 '18 at 16:46
  • @Karolis thanks for the tip. I tried it, but its still not redirecting to www – Adam Feb 17 '18 at 16:49
  • @Adam Your website gets perfectly redirected from http to https, and from non-www to www. It's clearly the problem of rule ordering. Clear the cache or reopen a new private window for testing after every change in htaccess file. – Karolis Feb 17 '18 at 17:03
  • @Karolis are you sure? I cleared cache & restarded my pc but if I enter `https://coaching-institutes.net` there is no redirect happening see [https://image.ibb.co/isECi7/Bildschirmfoto_vom_2018_02_17_18_06_59.png](https://image.ibb.co/isECi7/Bildschirmfoto_vom_2018_02_17_18_06_59.png). I also tried it on 2 other computers and no redirect happend there aswell, so I am very surprised that you say it works on your PC. Are you sure? – Adam Feb 17 '18 at 17:09
  • @Karolis I have a new idea: Maybe the .htaccess is not even executed in Firefox, because I have no certificate for the `https://coaching-institutes.net` and thus its not redirected? But strange that it works in Chrome.. – Adam Feb 17 '18 at 18:07
  • @Adam Yes I was sure, I meant the rules worked fine *separately*. As for `https://coaching-institutes.net` (i.e. https+non-www), you're absolutely right, this will never get redirected anywhere because you don't have a certificate for it. But http+www and https+non-www may get easily redirected to https+www with the *correct rule ordering*. Just don't promote https+non-www version anywhere on the web and nobody will use it because nobody types protocol names (i.e. `https://`) in the address bar by hand. – Karolis Feb 17 '18 at 18:17
  • The answer is legit what i said like 300 times, wtf. http://prntscr.com/igd584 http://prntscr.com/igd5a7 – user9373919 Feb 18 '18 at 11:40