[OJS 3.1.2-1] Journal statistic

@dung, thank you! However this does not seem to work in our case. And I still suspect there is some bug here. For we have already had a rewriting rule, that should work for all such cases. Here it is:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SERVER_NAME} ^mirros.hse.ru$ [NC]
RewriteRule ^(.*)$ index.php/mirros/$1 [L]

I can see the correct call to the API, e.g. when I go to Submissions in the back-end:

However, it this does not work when I go to Statistics --> Articles:

So we are a bit puzzled now :frowning:

@Ph_We Hi, Where did you put your RewriteRules? Show me the RewriteRules section if you can. Your RewriteRules is wrong in relation to Statistic and you are almost there.

1 Like

It is in the .htaccess:

AcceptPathInfo on
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SERVER_NAME} ^[mirros.hse.ru](http://mirros.hse.ru)$ [NC]
RewriteRule ^(.*)$ index.php/mirros/$1 [L]

It is the only RewriteRule we managed to make work for our instance of OJS with multiple journals so far :frowning:

if you read [Solved] Problems with api submissions error on submissions page - #4 by ctgraham
you will see that @ctgraham uses directives at an Apache virtualhost level to simplify the task. Even Apache document said so ( .htaccess files at the expense of some additional complexity.) Apache mod_rewrite Introduction - Apache HTTP Server Version 2.4

I will give you working example for virtual host RewriteRules if you want? Sorry but I will not be able to help with .htaccess RewriteRules.

@Ph_We,

If you want to do RewriteRules in virtualhost sections here is how: in your /etc/apache2/site-enabled/ find your config file such as 000-default.conf and add each section like the below for every journal.

<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerName abcd.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/gjhgjgjern

        RewriteEngine On
        # Rewrite index requests to the journal index
        RewriteRule ^/(index.php)?/?$ /index.php/abcd/index [L]

        # Rewrite custom domain to make api calls correctly
        RewriteRule ^/(api/.*)$ /index.php/abcd/$1 [R,L]

        # if the incoming request references the journal shortname, use an external redirect to strip the journal shortname
        RewriteRule ^/abcd/(.*)$ /$1 [R,L]

        # Normal request processing
        # Ignore if this request references index.php already
        RewriteCond %{REQUEST_URI} !/index.php/
        # Ignore if request is for a known OJS directory (Apache 2.2+)
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-d
        # Ignore if request is for a known OJS file (Apache 2.2+)
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f

        # Otherwise, rewrite all requests through index.php to this specific journal shortname
        RewriteRule ^(.*)$ /index.php/abcd/$1 [QSA,L]

        SSLEngine On
        SSLCertificateFile /sdfdf/asdfdf/cxvxcv/dfsdfds.crt
        SSLCertificateKeyFile /sdfdf/asdfdf/xcvxcvxc/sdfsdfd.key
        SSLCertificateChainFile /sdfds/apsdfs/xcvxcvxc/sfsdfsdfs.crt

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info xcvxcvxcv:warn

        ErrorLog ${APACHE_LOG_DIR}/brwqrwsf_error-xvcxv.log
        CustomLog ${APACHE_LOG_DIR}/sfweradsa_access-dsdsdsa.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
1 Like

Or if you want to stick with RewriteRules in .htaccess you will need to resolve that error 404 Not Found and your Statistic will work, we had the exact same issue and we fixed that with rules:

Rewrite custom domain to make api calls correctly

    RewriteRule ^/(api/.*)$ /index.php/abcd/$1 [R,L]

Where “abcd” is your “mirros”

This is what you api should return then the Stat will show

https://jmss.org/index.php/jmss/api/v1/stats/publishedSubmissions?count=20&offset=0&dateStart=2019-05-20&dateEnd=2019-06-19&timeSegment=month&orderBy=total&orderDirection=DESC&_=1561096128768

Dung.

1 Like

@dung, thank you so much for your help, will try it tomorrow.

1 Like

We’ve only managed to set up rewriting for this certain journal out of 23 so far. And this had to be set up in both .htaccess and VirtualHost. @dung, thanks once again.

@asmecher, (just to make it clear) Is there a reason why this certain API call should be different from any other? It might be really difficult to set this up in some cases.

@Ph_We Hi,

You may try something like this on your .htaccess (you need to target api path because that is your exact problem. Try and that may be it!

# Rewrite custom domain to make api calls correctly
RewriteRule ^/(api/.*)$ /index.php/mirros/$1 [R,L]

AcceptPathInfo on
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SERVER_NAME} ^[mirros.hse.ru](http://mirros.hse.ru)$ [NC]
RewriteRule ^(.*)$ index.php/mirros/$1 [L] 

Dung.

1 Like

You only need to set RewriteRules in either Virtualhosts or .Htaccess and not both. Both is confusing. Best in Virtualhosts as mentioned above.

D.

1 Like

Hello,

We are using OJS 3.1.2-1 We host several journals which have their own domain name.
We have the same problem. Some statistic pages do not display with a “404 Not Found” error.

We have rewrite rules in .htaccess file like this:

RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_NAME} ^journal-domain1.fr
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/journal1/$1 [QSA,L]

It works fine but not for the following URL:
https://journal-domain1.fr/api/v1/stats/publishedSubmissions

There is a “404 Not Found” error.

I tried several additional rules but it doesn’t work.

Is anyone has an idea ?

Thanks in advance.
Best regards.
Helene

@hcl Can you tell me if this url will return any result? I can not test your dns.

https://journal-domain1.fr/index.php/journal1/api/v1/stats/publishedSubmissions

Dung.

Hi @dung,

Yes, the following URL works:
https://journal-domain1.fr/index.php/journal1/api/v1/stats/publishedSubmissions

I don’t understand why, by the way. I thought my rewrite rule skipped all “index.php/journal1” url part.
Do you have any idea of which additional rule should I have to add to make it work?

Thanks again.
Best regards.
Helene

Hello @hcl,

Try to replace your 5 lines above with theses

RewriteEngine On

# Rewrite index requests to the journal index
RewriteRule ^/(index.php)?/?$ /index.php/journal1/index [L]

# Rewrite custom domain to make api calls correctly
RewriteRule ^/(api/.*)$ /index.php/journal1/$1 [R,L]

Next time please send the entire section

<VirtualHost *:443>
...
...
...
</VirtualHost>

Hi @dung,

I can’t send the entire section of VirtualHost because our rewrite rules are not in VirtualHost but in .htaccess file.
The rewrite rules you suggest don’t work for us because it changes all the previous rules and journals are not accessible any more to the base url: https://journal-domain1.fr/

On the other hand, I noticed that when I remove {contextPath} in “/lib/pkp/classes/handler/APIHandler.inc.php” file in “getEndpointPattern” function the following URL works:
https://journal-domain1.fr/api/v1/stats/publishedSubmissions

But it’s not the solution for all journals.

Best regards.
Helene

Please read [OJS 3.1.2-1] Journal statistic - #13 by Ph_We
Sorry that I can not help with .htaccess. I have always used virtual host configuration - the recommended and not complicated way of doing this.

Hi @asmecher,

I’m writting to you for this topic to ask you if you know the reason why URLs of stats with “api/v1” don’t work like other URLs when we have rewrite rules ?

We have rewrite rules in .htaccess file like this:

RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_NAME} ^journal-domain1.fr
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/journal1/$1 [QSA,L]

It works fine for all URL such as:

But not for the following URL:
https://journal-domain1.fr/api/v1/stats/publishedSubmissions
There is a “404 Not Found” error.
But the following URL works:
https://journal-domain1.fr/index.php/journal1/api/v1/stats/publishedSubmissions

And I noticed that when I remove {contextPath} in “/lib/pkp/classes/handler/APIHandler.inc.php” file in “getEndpointPattern” function the following URL finally works:
https://journal-domain1.fr/api/v1/stats/publishedSubmissions

But it’s not the solution for all journals.

Can you explain me the reason why and what can I do to solve this ?

Thanks in advance for your answer.
Best regards.
Helene

Hi @hcl,

This is filed and will get attention soon at API calls fail if context path is obscured by RESTful URL configuration · Issue #4919 · pkp/pkp-lib · GitHub – I’d suggest watching that issue for an update.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

3 posts were split to a new topic: [OJS 3.1.2.4] Blank statistics after upgrade

Has anyone resolved an issue with blank statistics view? More about this is written at [OJS 3.1.2.4] Blank statistics after upgrade - #8 by Lazar_Stosic but the problem still exist.