[Solved] Problems with api submissions error on submissions page

ojs3
#1

Hi

I have the same problem as many others with a multijournal OJS 3.1.1.4 with multiple domains.

I get the ##api.submissions.unknownError## error for the submissions page for our journal that has its own domain: mydomain.se/

According to the error handling in Firefox it tries to find:
https://mydomain.se//mydomain/api/v1/_submissions?....
which leads to a 404 error.

However this works in the address bar:
https://mydomain.se/index.php/mydomain/api/v1/_submissions?....

I am using .htaccess configuration (see below) and restful_urls. I have added base_urls for all the journals. (The following settings in config.inc.php)
base_url[index] = https://domain2.se
base_url[journalx] = https://domain2.se/journalX
base_url[mydomain] = https://mydomain.se

I tried these settings: How to remove index.php in ojs 3.0.2.0 and the proposed settings in the same thread by Tarcisio_Pereira

This [Solved] Custom domain error ##api.submissions.unkownError## on OJS3.1.1 does not work

Checked this as well: Error in upgrading OJS 3.0.2 to OJS 3.1.1

I can not solve it!
Can you please help me?

Here is my .htaccess file:

 RewriteEngine On

 RewriteBase /


# List of actual folders I want to access (like http://mydomain.com/folder1/)
RewriteRule ^(folder1|test)($|/) - [L]


 RewriteCond %{HTTP_HOST} domain1\.se$ [NC]
 RewriteRule ^(.*)$ https://domain2.se/$1 [L,R=301]

# Redirect www.mydomain.com to mydomain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]


# Remove index.php
RewriteCond %{SERVER_NAME} ^domain2\.se
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

# Handle api calls in subdomains
RewriteCond %{SERVER_NAME} ^mydomain\.se$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !api\/v1\/
#RewriteRule ^(.)$ index.php/mydomain/$1 [L]
#RewriteCond %{REQUEST_URI} api\/v1\/
#RewraiteRule ^(.*)$ index.php/mydomain/$1 [L]
RewriteRule ^(.*)$ index.php/mydomain/$1 [L]

# Handle subdomains
RewriteCond %{SERVER_NAME} ^mydomain\.se$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/mydomain/$1 [L]

# Remove index.php
RewriteCond %{SERVER_NAME} ^mydomain\.se
#RewriteCond %{SERVER_NAME} ^(www\.)?mydomain\.se
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/mydomain/$1 [L]
0 Likes

Error in upgrading OJS 3.0.2 to OJS 3.1.1
#2

I think a bit of your logic in the .htaccess rules has been lost in anonymizing the content.

Most related to your issue however might be the following:

# Handle api calls in subdomains
RewriteCond %{SERVER_NAME} ^mydomain\.se$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !api\/v1\/
RewriteRule ^(.*)$ index.php/mydomain/$1 [L]

This says, if the server name is “mydomain.se” and the request does not match an existing file, and the request does not match “api/v1/”, then route the request through “index.php/mydomain”. Why exclude api requests here?

1 Like

#3

Dear @ctgraham

Thank you for your reply!

Yes, it is probably wrong. I tried both to exclude and include the api addresses but nothing seems to affect it!
I guess there is a coding bug somewhere! See my reply to: Error in upgrading OJS 3.0.2 to OJS 3.1.1 and the work-around by @Gecuimar.

The Best
Edvin

0 Likes

#4

All requests to be handled by OJS (API or otherwise) are expected to be processed through OJS’s index.php.

I use the following standard re-write rule to accomplish this at the journal level:

    # If the URI already has index.php in it, don't change it
    RewriteCond %{REQUEST_URI} !/index.php/
    # Skip existing directories if Apache 2.2 or later
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    # Skip existing files if Apache 2.2 or later
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    # Skip existing directories if Apache prior to 2.2
    RewriteCond %{REQUEST_FILENAME} !-d
    # Skip existing files if Apache prior to 2.2
    RewriteCond %{REQUEST_FILENAME} !-f
    # Rewrite all other requests to a specific journal in OJS
    RewriteRule ^(.*)$ /index.php/JOURNALNAME/$1 [QSA,L]

I can confirm that this works for OJS 3.1.1-4.

My deployment uses these directives at an Apache virtualhost level, which greatly simplifies the work, because the virtualhost determines which journal is being accessed. To make this same strategy work in an .htaccess file in one Apache virtualhost which is handling multiple different domain names should be possible, but you would need to repeat this directive for each journal, with exclusion criteria so that it does not operate on every other possible domain name.

0 Likes

Restful URLs on OJS3
Each journal with its own domain name
#5

Dear @ctgraham

I tried very hard on this.

I move the settings to .conf files, and added AllowOverride None to the .conf file and/or remvoded the .htaccess file.

Then my custom domain for one of my journals “mydomain.se” redirects to the index main site “domain2.se” above.

This is my conf-file:

<Directory "/var/www/html/">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride Fileinfo
            DirectoryIndex index.php

            RewriteEngine on
            RewriteBase /
            # If the URI already has index.php in it, don't change it
            RewriteCond %{REQUEST_URI} !/index.php/
            # Skip existing directories if Apache 2.2 or later
            RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
            # Skip existing files if Apache 2.2 or later
            RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f

            # Skip existing directories if Apache prior to 2.2
            RewriteCond %{REQUEST_FILENAME} !-d
            # Skip existing files if Apache prior to 2.2
            RewriteCond %{REQUEST_FILENAME} !-f

            # Rewrite all other requests to a specific journal in OJS
            RewriteRule ^(.*)$ index.php/mydomain/$1 [QSA,L]
</Directory>

It looks like the commands in .conf file are not launched, and the system needs to find the commands in the .htaccess file.

0 Likes

#6

Does OJS live directly in /var/www/html here? That is, config.inc.php is found at /var/www/html/config.inc.php?

Based just on this snippet, is seems that RewriteBase / should be unnecessary. If it is added intentionally, there may be additional aliasing in place which could be affecting your re-writes.

Is this snippet contained in a single VirtualHost directive, multiple VirtualHost directives, or outside of any VirtualHost directives? There should be additional context here which may be relevant.

Did you restart Apache after modifying the config file? Changes to .htaccess will be processed immediately, but the config files are only reloaded after an Apache restart.

0 Likes

#7

Dear @ctgraham

Thank you for your help!

Yes, it is. However we might want to move it into a subfolder in future.

I tried both with and without that.

Yes, the file looks like this:
<VirtualHost *:80>
ServerName mydomain.se
DocumentRoot "/var/www/html/"
…snippet above…
ErrorLog "/var/log/httpd/xxx:80_error.log"
ServerSignature Off
CustomLog "/var/log/httpd/xxx:80_access.log" combined
</VirtualHost>
And then I have a similar file for the 443 port with generally the same content. And then a 80 and a 443 file for the main site.

Yes, I did.

/Edvin

0 Likes

#8

What actually happens when you try to access the server with this configuration? Do you get a server error, a redirect loop, or a partially loaded page?

Have you tried enabling the mod_rewrite logging to see what Apache is processing with the request?

0 Likes

#9

Dear @ctgraham

The problem with conf-files and .htaccess seemed to be related to the !-d command. Here is an output from the logging:
RewriteCond: input='/' pattern='!/index.php/' => matched
RewriteCond: input='/var/www/html//' pattern='!-d' => not-matched

I now removed the !-d commands and instead used the command as described elsewhere by @ajnyga How to remove index.php in ojs 3.0.2.0 :
RewriteRule ^(folder1|test)($|/) - [L]

However the main problem still remains.
But this work-around makes it work:

I use Apache/2.4.6 with CentOS.

The best,

Edvin

0 Likes

#10

The log lines are related to an index request (no path provided in the URI). They indicate that such a request matches the pattern of “does not contain /index.php/”, and does not match the criteria of “is not a directory”. The input “/var/www/html//” is a valid directory.

Do you have DirectoryIndex index.php set in your virtualhost? This enables Apache to respond to a directory request with the index.php file it contains.

0 Likes

#11

Dear @ctgraham

Yes,

is set in my virtualhosts

I will check the mod rewrite logging for the submissions. I will come back to you.

/edvin

0 Likes

#12

Dear @ctgraham and others!

Thank you @ctgraham for your help an patience!

I have solved this issue. I added mod_rewrite logging and got this error log when approaching the submissions page:

[Wed Feb 20 07:59:29.400006 2019] [rewrite:trace3] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] add path info postfix: /var/www/html/mydomain -> /var/www/html/mydomain/api/v1/_submissions, referer: https://mydomain.se/submissions
[Wed Feb 20 07:59:29.400075 2019] [rewrite:trace3] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] strip per-dir prefix: /var/www/html/mydomain/api/v1/_submissions -> mydomain/api/v1/_submissions, referer: https://mydomain.se/submissions
[Wed Feb 20 07:59:29.400083 2019] [rewrite:trace3] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] applying pattern '^(.*)$' to uri 'mydomain/api/v1/_submissions', referer: https://mydomain.se/submissions
[Wed Feb 20 07:59:29.400123 2019] [rewrite:trace4] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] RewriteCond: input='/mydomain/api/v1/_submissions' pattern='!/index.php/' => matched, referer: https://mydomain.se/submissions
[Wed Feb 20 07:59:29.400137 2019] [rewrite:trace4] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] RewriteCond: input='/var/www/html//mydomain/api/v1/_submissions' pattern='!-f' => matched, referer: https://mydomain.se/submissions
[Wed Feb 20 07:59:29.400146 2019] [rewrite:trace2] [pid 9527] mod_rewrite.c(470): [client x.x.x.x:3883] x.x.x.x - - [mydomain.se/sid#55cd7477b9b8][rid#55cd74992b80/initial] [perdir /var/www/html/] rewrite 'mydomain/api/v1/_submissions' -> 'index.php/mydomain/mydomain/api/v1/_submissions', referer: https://mydomain.se/submissions
...

It looks like the Rewrite-rules are adding “mydomain” to the URI multiple times.
I modified my apache conf-file by adding a RewriteCond to look for “mydomain” in the address.
Now my .conf file looks like this:

<VirtualHost *:443>
ServerName mydomain.se
DocumentRoot "/var/www/html/"
<Directory /var/www/html>
    AllowOverride None
    Options Indexes FollowSymLinks MultiViews
    Require all granted
    DirectoryIndex index.php
    RewriteEngine on
    RewriteBase /
    # If the URI already has index.php in it, don't change it
    RewriteCond %{REQUEST_URI} !/index.php/
    RewriteCond %{REQUEST_URI} !/mydomain/
    # Skip existing directories if Apache 2.2 or later
    #RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    # Skip existing files if Apache 2.2 or later
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    # Rewrite all other requests to a specific journal in OJS
    RewriteRule ^(.*)$ index.php/mydomain/$1 [QSA,L]

    # If the URI already has index.php in it, don't change it
    RewriteCond %{REQUEST_URI} !/index.php/
    RewriteCond %{REQUEST_URI} /mydomain/
    # Skip existing directories if Apache 2.2 or later
    #RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    # Skip existing files if Apache 2.2 or later
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    # Rewrite all other requests to a specific journal in OJS
    RewriteRule ^mydomain(.*)$ index.php/mydomain/$1 [QSA,L]
</Directory>

## Logging
 ErrorLog "/var/log/httpd/mydomain.se:443_error_ssl.log"
 ServerSignature Off
 CustomLog "/var/log/httpd/mydomain.se:443_access_ssl.log" combined
## Header rules
## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
 Header Set Strict-Transport-Security "max-age=31536000"

## SSL directives
...
</VirtualHost>
0 Likes

Error in upgrading OJS 3.0.2 to OJS 3.1.1