2

When trying to login to my live env on craft, I get the following error in the javascript console.

[Error] Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404) (login, line 0)

This only happens in the live environment, which is weird because the DB and front-end code are synced between local and live. There is also a staging website where the login page works.

  • 1
    Recently i faced the same issue, and it was due to ssl. – inrsaurabh Jun 11 at 7:26
5

So I looked into this a bunch more tonight to satisfy my curiosity, and here's what is happening.

The default rewrite rule that Forge is apparently adding is this:

if ($request_uri ~* "^(.*/)index\.php/?(.*)") {
    return 301 "$1$2";
}

What this does is essentially it just removes index.php from URLs, which seems harmless enough.

On the login screen, Craft has a JavaScript that does an XHR to the following URL:

/index.php/admin/actions/users/login

This matches the rule above, and gets rewritten as:

/admin/actions/users/login

The problem here is that redirects will never resend POST data and the request now becomes a GET.

Well, sure enough, the UsersController gets hit, and the actionLogin() method is called, but:

public function actionLogin()
{
    if (craft()->userSession->isLoggedIn())
    {
        // Too easy.
        $this->_handleSuccessfulLogin(false);
    }

    if (craft()->request->isPostRequest())
    {

enter image description here

...because the request is no longer a POST request, Craft bails, and request 404s, and everyone is unhappy.

So, how to fix it? Probably Forge should check for $request_method != POST before attempting the 301 redirect.

Solution: If you're using Craft, just remove the above rule, it isn't needed.

6

What server provisioner are you using? Forge? Something else? If it's Forge, it's most likely this:

https://twitter.com/nystudio107/status/895726366477344772

Also here are some Nginx configs (with Forge examples) that are known to work with Craft CMS 2.x and 3.x: Nginx-Craft

  • Wow thank you so much! I am using forge... weird that this happens in one environment but not another. I owe you a beer! – Clark Nelson Aug 16 '17 at 20:31
  • Is this a new development? Like in that last couple days? That config does not appear in older provisions. – Steve Mock Aug 18 '17 at 1:44
  • Yeah it must be fairly recent, because I I've created sites with Forge pretty recently, and this default config wasn't there. – andrew.welch Aug 18 '17 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.