Topic on Project:Support desk

api.php ends up in redirection loop

12
Summary by MarkAHershberger
Dominik Maus (talkcontribs)

I tried installing MW 1.30 onto my box (another mw 1.25 already runs there w/o problems). The wiki itself runs smoothly so far, but whenever I try to use the api.php, the browser reports a redirection error. I assumed a problem with my Apache Rewrite Rules and removed them completely, no success. According to google I've added $wgUsePathInfo = true; to the LocalSettings, no change. I assumed some incompatibility and tried MW 1.29.2 and MW 1.27.4 with the same result.

Please let me know if you need more info. Thanks.

Dominik Maus (talkcontribs)

An addition to the info: I tried to access api.php using lynx, which reported HTTP 301.

MarkAHershberger (talkcontribs)

Yep, and I verified this using

wget -S -O /dev/null http://m59wiki.webmaus.net/api.php

I got 20 of these before it stopped:

--2018-01-30 19:51:31--  http://m59wiki.webmaus.net/api.php
Reusing existing connection to m59wiki.webmaus.net:80.
HTTP request sent, awaiting response... 
  HTTP/1.1 301 Moved Permanently
  Date: Wed, 31 Jan 2018 00:51:31 GMT
  Server: Apache
  X-Powered-By: HHVM/3.17.1
  X-Content-Type-Options: nosniff
  Vary: Accept-Encoding
  Location: http://m59wiki.webmaus.net/api.php
  X-Powered-By: PleskLin
  Keep-Alive: timeout=5, max=80
  Connection: Keep-Alive
  Transfer-Encoding: chunked
  Content-Type: text/html
Location: http://m59wiki.webmaus.net/api.php [following]
20 redirections exceeded.

What are $wgScriptPath, $wgServer, etc. set to?

MarkAHershberger (talkcontribs)

Are you sure you've removed the .htaccess file for the site?

Dominik Maus (talkcontribs)

Yes, the .htaccess is deleted.

$wgScriptPath = "";

$wgScript = "{$wgScriptPath}/index.php";

$wgArticlePath = "{$wgScript}?title=$1";

$wgScriptExtension = ".php";

$wgServer = "http://m59wiki.webmaus.net";

$wgResourceBasePath = $wgScriptPath;

Dominik Maus (talkcontribs)

I was messing around a little bit more. I've installed an MW 1.25.1, this version's api.php worked. There must be some problem on newer versions.

MarkAHershberger (talkcontribs)

Hmmm... The only thing I can think of right now is that there is some confusion with the skin. Have you done any custom work there?

Dominik Maus (talkcontribs)

I am using the original vector skin, I've re-colored some of the pictures, but no code.

I believe there is some compatibility problem with either the hhvm version, or the mysql version. For example, the mw 1.30 required a newer mysql version than I am using. Maybe that's the issue with 1.26+ aswell. However I will stick to 1.25.6 which runs perfectly by now.

MarkAHershberger (talkcontribs)

I doubt the problem is with mysql. Just so you know, though, 1.27 is the oldest version currently supported.

Yaxu (talkcontribs)

I had the same problem. Eventually narrowed it down to some strange code at the top of api.php.

// Pathinfo can be used for stupid things. We don't support it for api.php at
// all, so error out if it's present.
if ( isset( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != '' ) {
       $correctUrl = wfAppendQuery( wfScript( 'api' ), $wgRequest->getQueryValues() );
       $correctUrl = wfExpandUrl( $correctUrl, PROTO_CANONICAL );
       header( "Location: $correctUrl", true, 301 );
       echo 'This endpoint does not support "path info", i.e. extra text between "api.php"'
               . 'and the "?". Remove any such text and try again.';
       die( 1 );
}

Pathinfo might be used for stupid things, but my guess is that it's also how nginx communicates with fastcgi, so the above results in a loop where api.php gets rid of the path info, and nginx puts it back in again. Anyway, I commented out the above and things work again.

Ciencia Al Poder (talkcontribs)

This line in the response seems to indicate another software is causing interferences:

X-Powered-By: PleskLin

This api is being intercepted by another application, not PHP. Check the rewrite rules on your server.

Ofbeaton (talkcontribs)

I ran into this problem myself, and found this thread through searching. I believe that the problem is as Yaxu said, your webserver configuration is setting PATH_INFO, which makes api.php fail, but no other entry points. I had <code>fastcgi_param PATH_INFO $fastcgi_script_name;</code> in my php-fpm config. Commenting this out solved the problem, though I wonder if it won't break some other applications on my server. I filed a bug https://phabricator.wikimedia.org/T215857

Reply to "api.php ends up in redirection loop"