API redirect problems in RESTful URL configuration (api.404.endpointNotFound)

Hi

I am running a single journal environment, with RESTful URLs on ojs-3.3.0-7, PHP 7.4.24, Apache 2.4.x in a shared hosting environment.

After logging in to admin panel, file upload requests I send either in the subscriber or management console are sent to /api/v1/_uploadPublicFile, but are being internally redirected to journal contextPath
/cp/api/v1/_uploadPublicFile and returning a 403. If I go to the URL (/cp/api/v1/_uploadPublicFile), I get an api.404.endpointNotFound

I tried going through the various recommendations in issue #4919 but have not found a solution.

config.ini.php

disable_path_info = Off
base_url = "https://www.journalname.com"
base_url[index] = https://www.journalname.com/ojsadmin
base_url[cp] = https://www.journalname.com

.htaccess

RewriteRule ^ojsadmin/(.*)$ index.php/ojsadmin/$1 [PT,QSA,L]
RewriteRule ^cp/api/v1/(.*)$  index.php/cp/api/v1/$1 [PT,QSA,L]

RewriteCond %{SERVER_NAME} ^www\.journalname\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/cp/$1 [PT,QSA,L]

Changing it from [PT,QSA,L] to [L] doesn’t make a difference.

I’ve had had to add the following to index.php to overcome the lack of PATH_INFO variables to fix initial routing, but I don’t believe this related:

if (getenv('ORIG_PATH_INFO')) {
    putenv("PATH_INFO=".getenv('ORIG_PATH_INFO'));
}
if ($_SERVER['ORIG_PATH_INFO']) {
    $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
}
if ($_ENV['ORIG_PATH_INFO']) {
    $_ENV['PATH_INFO'] = $_ENV['ORIG_PATH_INFO'];
}

My browser includes these requests:

jquery.min.js?v=3.3.0.7:2 XHR finished loading: POST "https://www.journalname.com/api/v1/_uploadPublicFile".
jquery.min.js?v=3.3.0.7:2 XHR finished loading: GET "https://www.journalname.com/api/v1/_uploadPublicFile/".
jquery.min.js?v=3.3.0.7:2 GET https://www.journalname.com/cp/api/v1/_uploadPublicFile 403
jquery.min.js?v=3.3.0.7:2 XHR failed loading: GET "https://www.journalname.com/cp/api/v1/_uploadPublicFile".

Error_logs produce one entry:

[16-Oct-2021 13:08:33 America/Chicago] REQUEST_URI: /cp/api/v1/_uploadPublicFile PATH_INFO: /cp/api/v1/_uploadPublicFile

Any ideas?

To add to the issue

When I specify:

base_url[cp] = https://www.journalname.com

I get the /cp/api/v1/_uploadPublicFile and returning a 403
But when I put in:

base_url[cp] = https://www.journalname.com/cp

It works. In the first instance, $slimRequest->getAttribute(‘route’) is blank in ApiAuthorizationMiddleware.inc.php

How do I get around the missing route attribution when my journal is named ‘cp’, I don’t want this in the PATH, and I want the API router to assume this is the path I’m using if the route is not found?

Fixed after lots of digging. Our final solution was to redirect the API calls for each contextPath using R=307 to tell Apache to redirect POST data for each root domain separately to avoid missing context problems.

See this post for the config.inc.php and .htaccess changes that eventually worked: https://github.com/pkp/pkp-lib/issues/4919#issuecomment-945949086

It would be great to have a few different examples of route handling for different contextPath scenarios and restful URL combinations in the docs/FAQ on RESTful URL and RewriteRule handling.

2 Likes

This topic was automatically closed after 5 days. New replies are no longer allowed.