# Intermittent API JSON 404 errors in 3.1.2.4

Sorry to bring this up again, but I’m getting the following API 404s when logging into the dashboard (although not consistently – but often when it happens, I’m immediately logged out).

The following URLs are called:

https://journaldomain.org//[acronym]/api/v1/_submissions?status=1&assignedTo=-1&searchPhrase=&count=20&offset=0&_=1615574988136
https://journaldomain.org//[acronym]/api/v1/_submissions?status=1&searchPhrase=&count=20&offset=0&_=1615574988137
https://journaldomain.org//[acronym]/api/v1/_submissions?status%5B%5D=4&status%5B%5D=3&searchPhrase=&count=20&offset=0&_=1615574988138


Note the lack of index.php between the domain and the acronym.

I’m sure this is to do with url rewriting. Here are the contents of my htaccess:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$index.php/$1 [QSA,L]
</IfModule>


and relevant parts of config.inc.php:

base_url = "https://journaldomain.org"
disable_path_info = Off
allow_url_fopen = On
; base_url[index] = https://journaldomain.org/[acronym] // commented
; base_url[acronym] = https://journaldomain.org/[acronym] // commented
; base_url[myOtherJournal] = http://myOtherJournal.myUrl.com // commented


I should say that sometimes the above URLs work – I can see the JSON response and 200 success code in dev tools, which is why it’s so strange that it’s intermittent.

Any help would be much appreciated!

Can anyone help?

The only php errors I see are End of script output before headers: index.php, so I can’t diagnose the issue. I would like to change to PHP-FPM (I suspect PHPCGI might be the problem) but I can’t do that just yet because the rewrite doesn’t work with FPM

EDIT:

I temporarily enabled displayed errors in config.inc.php, and got this detail:

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 35

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 36

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 37

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 38

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 39

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 40

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 41

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 42

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 43

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 45

Warning: session_set_save_handler(): Cannot change save handler when headers already sent in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 53

Warning: session_start(): Cannot start session when headers already sent in /home/journalckm/www/lib/pkp/classes/session/SessionManager.inc.php on line 58

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/journalckm/www/lib/pkp/lib/adodb/adodb.inc.php on line 1003

Warning: Declaration of MathJaxPlugin::register($category,$path) should be compatible with LazyLoadPlugin::register($category,$path, $mainContextId = NULL) in /home/journalckm/www/plugins/generic/mathjax/MathJaxPlugin.inc.php on line 72 Warning: Declaration of CoinsPlugin::register($category, $path) should be compatible with LazyLoadPlugin::register($category, $path,$mainContextId = NULL) in /home/journalckm/www/plugins/generic/coins/CoinsPlugin.inc.php on line 133

Warning: Declaration of UsageStatsOptoutBlockPlugin::getBlockContext() should be compatible with BlockPlugin::getBlockContext(\$contextId = NULL) in /home/journalckm/www/plugins/generic/usageStats/UsageStatsOptoutBlockPlugin.inc.php on line 104

Deprecated: Non-static method PKPRequest::redirect() should not be called statically in /home/journalckm/www/lib/pkp/classes/security/Validation.inc.php on line 178

Deprecated: Non-static method PKPRequest::_checkThis() should not be called statically in /home/journalckm/www/lib/pkp/classes/core/PKPRequest.inc.php on line 718

Warning: Cannot modify header information - headers already sent by (output started at /home/journalckm/www/lib/pkp/lib/adodb/adodb.inc.php:263) in /home/journalckm/www/lib/pkp/classes/core/PKPRequest.inc.php on line 99


This looks like it could be part of the issue! I’m running php 7.3, fwiw.

Hi @laurenced,

The Headers already sent messages are just related to error messages being directed to the browser; make sure they’re sent to the log instead, and they’ll go away.

I do think this is related to your rewrite rules, and I’m afraid I can’t help with those in detail. Try disabling the rewriting and use the default URLs (including the index.php part of the URLs). That should get your system working 100%. From there, you’ll need to work on your rewrite rules – if they’re configured correctly they should be 100% invisible to OJS. (The only part OJS needs to think about is how to generate URLs, and that’s what the config.inc.php base_url[...] settings do.)

Regards,
Alec Smecher
Public Knowledge Project Team

This may be related to this issue. You may want to create a test instance and upgrade to 3.2, where the URL construction has been changed in the submission lists.

A post was split to a new topic: 404 error when accessing administration page

Thanks Nate!

I’ve upgraded to 3.3.0.4, which seems mostly to have worked, however I now can’t access the Administration page in the dashboard – I get a 404. The menu link doesn’t include the journal path, so it looks like mydomain.org/index/admin instead of mydomain.org/journal/index/admin or mydomain.org/index.php/index/admin (which loads when entered manually, except CSS and JSON calls mostly fail).

Is there a change to htaccess that should be made for such an upgrade path? I searched the docs but can’t find anything about it.

Hmm, I’m not very familiar with how the URLs work with a base_url as a domain. I think everything should be accessed without the /journal-path/ in the URL, but I’m not sure. Let me check with someone who knows more.

We do something like this by accessing the index path on a different subdomain. E.g.:

base_url = https://admin.myjournal.org/

It should be possible to create a mod_rewrite directive which treats the index path as an exception to the general rewrite, but it will be complex and feels brittle to me.