Restfull urls not working with base_url and mod_rewrite.c

  • Application Version - ojs-3.2.1-1

I have 6 journails and all of them have their base_url. When i try to access the admin panel of a journal, all the api calls are failing because of the rewriting is not working.

I know that because when i put myself the index.php the api call work.

http://revista-estudios-revistas.deusto.es/revista-estudios/api/v1/submissions?status=1&assignedTo=-1&searchPhrase=&count=20&offset=0&=1595497077985 NOT FOUND

because is not working the re-writing

and this one is working:
http://revista-estudios-revistas.deusto.es/index.php/revista-estudios/api/v1/submissions?status=1&assignedTo=-1&searchPhrase=&count=20&offset=0&=1595497077985

thanks.

What are you using for your re-write rules?

Hi!
I use .htaccess. It is look like this. One entry like this for each journal:
RewriteEngine On
RewriteBase /

Use this set of 3 lines for each of your journals

RewriteCond %{SERVER_NAME} ^JOURNALURL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/journal/$1 [L]

The config of the system has diseable the option:
restful_urls = Off

I have been trying also with this config option enabled.

This set of rules requires Apache 2.2 or earlier (may be ok, depending on your server) and seems to be a mix of restful URLs and hiding the journal shortname, (doesn’t seem to be ok, based on your examples).

Please read through these commented sample rewrites, which may help to give a better understanding of what each line is doing:

Note that the config.inc.php option restful_urls represents removing “index.php” from the URL.

Note that removing the journal shortname from the URL may get extremely complicated in an .htaccess file. It doesn’t look from your sample URL that you are trying to do this, but your rewrite rule looks like it is.

I am using Apache/2.4.29 (Ubuntu)

My journals have to have diferent urls such as http://www.tuningjournal.org/. So i need to convert this to SERVER_NAME/index.php/tuningjournal/ and for this reason i have this rules in the .htaccess. But the api calls are not re-write correctly because the index.php is missing but only in the api calls:
image

I need this : http://revista-estudios-revistas.deusto.es/index.php/tuningjournal/api/
but i have this http://revista-estudios-revistas.deusto.es/tuningjournal/api/… so that it is not working

I am not sure if i am expleaning myself properly because of my english level.

Another thing…i am not understang why i need to do that because if i put in the config file de base_url options the core of the aplication have to understand that http://www.tuningjournal.org/ is SERVER_NAME/index.php/tuningjournal/ . Is this funtionality working in any instalation?

The settings in config.php tell OJS how to present the URLs in the interface, but the settings cannot tell Apache how to route the requests to OJS.

So, both setting the base_url and restful_url settings in config.inc.php, and configuring mod_rewrite in Apache are required for this to work.

Please share your mod_rewrite configuration here and your base_url configuration here, and we may be able to help identify what is wrong.

In your configuration, you are using rewrites and base_url entries as if restful_urls is “On” in config.inc.php.

I would add a RewriteCond to not rewrite requests which already have a “/index.php/” within the path.

I presume the variable %{REQUEST_FILENAME} is working for you in 2.4 because these rules are in .htaccess rather than a VirtualHost. Note that this may not perform as expected when Apache has not already been able to fully determine the value at the time of reference.

The sample code adds a QSA flag to the RewriteRule, but this shouldn’t have a positive or negative effect in your case.

On an outside chance, I would also add DirectoryIndex index.php index.html to ensure PATH_INFO isn’t being given the wrong filename internally.

None of the above in my mind is a certain fix for what you are seeing. I think your next step would be to turn on tracing with mod_rewrite to try to identify the issue.

The HTTP 307 redirect in .htaccess helped me with the redirect for the submissions page and image uploading: [OJS 3.2.0.3] Error on Submission Page - #24 by KBodarwe

2 Likes

thanks. This solved my problem with the api calls :slight_smile: I have to test all the installation but it is promising

1 Like