Page MenuHomePhabricator

VisualeEditor: Error contacting the Parsoid/RESTBase server (HTTP 404)
Closed, ResolvedPublic

Assigned To
Authored By
Kghbln
Dec 17 2020, 11:48 AM
Referenced Files
None
Tokens
"The World Burns" token, awarded by Orribu."The World Burns" token, awarded by Kghbln."The World Burns" token, awarded by TiltedCerebellum.

Description

Setup

  • MW 1.35
  • VisualEditor REL_1_35

Issue
If one wants to use VisualEditor with a short URL like e.g. https://wiki.example.org/Main_Page you will get "Error contacting the Parsoid/RESTBase server (HTTP 404)" Once you add an URL particle (not sure how to call it) like page as in e.g. https://wiki.example.org/page/Main_Page everything works as expected. Thus it appears that currently having this URL particle is required.

works for https://wiki.example.org/page/Main_Page

LocalSettings.php

$wgScriptPath = "/mediawiki";
$wgArticlePath = "/page/$1";

VirtualHost

<IfModule mod_rewrite.c>
        RewriteEngine on

        RewriteRule ^/?page(/.*)?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
        RewriteRule ^/?$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
</IfModule>

does not work https://wiki.example.org/Main_Page

LocalSettings.php

$wgScriptPath = "/mediawiki";
$wgArticlePath = "/$1";

VirtualHost

<IfModule mod_rewrite.c>
        RewriteEngine on

        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
        RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
</IfModule>

Perhaps some extra voodoo is to be added to the rewrite rules to also make something like https://wiki.example.org/Main_Page possible but I do not know what it could be.

Created this report to make you aware however I suspect that this may be a dupe already.

Event Timeline

Kghbln updated the task description. (Show Details)

I'm also having this issue. I've tried the troubleshooting steps provided on the extension page, but to no avail. I think my wiki is a private wiki...don't know if that has anything to do with the issue.

I did some snooping on my end; had a fresh install of Mediawiki 1.35.1 ready to go. Visual Editor works right out the box, but as you said, the second you shorten the link, everything breaks and we get a 404. I found that editing my .htaccess file didn't do anything, but the second I added

$wgScriptExtension = ".php";
$wgArticlePath = "/$1";

everything broke. I don't know what we're missing...

@Orribu Thanks for confirming that you have this issue too. $wgArticlePath is fine for this kind of short URLs. PS You can safely remove $wgScriptExtension since this parameter does no longer exist since MW 1.27 or so.

@kghlbn Thank you for the follow-up and the tip! I've removed $wgScriptExtension from LocalSettings.
I'll keep an eye on this space for any updates!

I think I found the solution.
You can use RewriteRule ^(?:(?!rest.php/).)*$ %{DOCUMENT_ROOT}/index.php [L] instead of RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]
Because acording to the document, VE would fetch urls like [http://your-wiki-base-url]/rest.php/v1/page/Main_Page, which would redirect to index.php unexpectedly.

update: I just paste what I use in my setup, you may have a different path to index.php.

Thanks @Func for providing a possible solution. However, to my regret, it does not work for me. I get redirection errors after changing the rewrite rule.

Ah, I just copied over your suggestion without looking at it in detail. The path to "index.php" was incorrect. Now with the adjusted rewrite rule, it works for me. Will do more testing but so far it appears to be fine. This is cool:

<IfModule mod_rewrite.c>
        RewriteEngine on

        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
        RewriteRule ^(?:(?!rest.php/).)*$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]
</IfModule>

I believe you just helped quite some people out of their misery. :) It will be great if others could test and verify too, before I add this to the documentation.

Thank you both for this, will test also.

Excellent, I confirm this works for me too with the subfolder added to the URL! Kudos to you @Func, this had been open for a long time...

Heya, I've tested it and it works like a charm so far! Ohhh my goodness thank you so much @Func !!!

Kghbln claimed this task.

Indeed, great solution from @Func! I now documented the solution on wiki.

@Ciencia_Al_Poder The solution is obviously Apache centric. If I am not mistaken you are an heavy user of Nginx. I assume that the issue will occur there too. If you have a solution it will be great if you could also document it here. Never mind if you do not have one. Cheers

I don't think nginx users would encounter this problem, since the way it handles rewrites is very different

The short URL page about nginx seems to already cover that: https://www.mediawiki.org/wiki/Manual:Short_URL/Nginx

Thanks a lot for this information. Lucky you. :) I adjusted the documentation accordingly to make clear that Apache is affected.

I got this working with the following:

Installation directory: /var/www/html/mediawiki
Doc root: /var/www/html

In LocalSettings.php:

$wgScriptPath = "/mediawiki";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

In apache vhost:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mediawiki/rest\.php
RewriteCond %{REQUEST_URI} !^/mediawiki/api\.php
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/mediawiki/index.php [L]

Thanks for sharing your alternative solution. I suspect though that it is out of scope of this issue since we are working on a solution for $wgArticlePath = "/$1";. Something like $wgArticlePath = "/wiki/$1"; should work without extra voodoo.

Thanks for sharing your alternative solution. I suspect though that it is out of scope of this issue since we are working on a solution for $wgArticlePath = "/$1";. Something like $wgArticlePath = "/wiki/$1"; should work without extra voodoo.

I think it is still in scope. You can change the $wgArticlePath to /$1 without issue in this configuration and it's cleaner due to the RewriteCond's. The critical part you might have missed is that mediawiki is not the doc root but still gets rewritten to example.com's url root. I add $wgArticlePath = "/wiki/$1"; because it's still clean and prevents critical article collisions and security issues with the docroot php files. Try it, should work.

One of the reasons this breaks in apache AND nginx is that rest.php takes both path based arguments mixed with url variable arguments which is...odd.

Here's the fix for nginx too:

location /api.php {
        try_files $uri $uri/ /api.php?$args;
}

location /rest.php {
        try_files $uri $uri/ /rest.php?$args;
}

Note: You need to point rest.php and api.php at the correct path for your webroot. E.g.:

location /mediawiki/api.php {
        try_files $uri $uri/ /mediawiki/api.php?$args;
}

location /mediawiki/rest.php {
        try_files $uri $uri/ /mediawiki/rest.php?$args;
}

Enjoy <3

In the end do not fully grok what the web servers do here as long as they do what they should. Thank you for following up and elaborating a bit. I guess this is great information we all can use to improve.