How to remove index.php in ojs 3.0.2.0

Dear staff,
I installed the ojs 3.0.2.0 in www.XXX.com/journals/. There are some journals in url like www.XXX.com/journals/index.php/journal 1
Everything is very good. But I wish to remove index.php in url. I have tried to follow the instruction in forum to set config.inc.php and create .htaccess to remove index.php in url. No matter what I set, I always get the same results

  1. the webpage lost css and became weird in www.XXX.com/journals/
  2. it has removed the index.php in url from link of www.XXX.com/journals/, e.g. the link become www.XXX.com/journals/journal 1, but the webpage showed "No input file specified. ".
    Could you give me some more instruction about removing index.php?

Thank you in advance.

Best regards

At least in our case the exact settings we had in OJS2 worked in OJS3 as well:

3 Likes

Yes, I followed this method. But the webpage loss all css style and the url without index.php showed "No input file specified. " Did you test this method in ojs 3.0.2.0?

Best regards

Yes, we have this in our site and it is working. I can check our exact settings on Monday.

Dear Ajnyga. I will very appreciate if you would tell me the exact setting.
By the way, do you know how to set subdomain for each journals? I think this is also a problem related with URL rewriting.
Thank you in advance.
Best regards

We have subdomains as well. We use wildcard domains meaning that you need more than just OJS settings.

Dear ajnyga
Are you happy to help me further to set everything about subdomain and removing index.php? My email address is libuyi2008@gmail.com. If you are happy to help, please contact me.
Thank you in advance.
Best regards

I can post our .htaccess and config.inc.php settings here. Setting up wildcard subdomains depends on your service provider so I can not help you much there.

Thank you for your kind reply. Could you tell me more details about wildcard subdomains which I will forward to my service provider? I don’t know much in this area.

Best regards

Hi,

Here are the settings from my .htaccess and config.inc.php that are related to the issue:

Contents of .htaccess

RewriteEngine On
RewriteBase /

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

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

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

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

The first rule is just for ensuring I can access a few folders, not necessary.
The second rule just redirects www.domain.com to just domain.com, not necessary
The third set of rules removed index.php, you could use just that if it is enough
The fourth set of rules handles the subdomains. For this to work you need to define the subdomains in config.inc.php and have wildcard domains active.

Contents of config.inc.php (not all of it of course)

base_url = "http://mydomain.com"
disable_path_info = Off

base_url[journal1] = http://mydomain.com/journal1
base_url[journal2] = http://mydomain.com/journal2
base_url[journal3] =  http://journal3.mydomain.com
base_url[journal4] =  http://journal4.mydomain.com

restful_urls = On

Here the most important setting is the restful_urls setting. You need it to be on both when you are removing index.php and/or are using subdomains.
The base_url settings for the journals are necessary only if you are using subdomains. However, if you choose to use subdomains and define even one of them here, you need to define all of the journals base_url’s. If you do not, all the other journals will stop having their metrics saved.
In this example journal3 and journal4 are using subdomains. The two other journals are using the ordinary url.

I am happy to hear if I could make the settings better somehow or if there are any problems I have not seen, @ctgraham? For us these settings seem to work.

Edit: I see now that our settings were actually a bit different, but I am fairly sure that these are originally form some thread in the forums.

5 Likes

That configuration looks reasonable to me.

1 Like

I just can’t figure out why I ended up removing RewriteCond %{REQUEST_FILENAME} !-d and adding the rule for specific folders. I probably have to test and see if it makes a difference. I already wrote that almost a year ago for OJS2.

Ah, I missed that part. Are these non-OJS folders your are specifying?

Yes, I have a feeling I had some problems with those and ended up with the solution above.

With OJS 3.1.1.2 there will be errors if you use the settings I posted above. These are the ##api.submissions.unkownError## errors that a lot of users have encountered.

This is the new config that seems to work.

RewriteEngine On
RewriteBase /

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

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

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

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

# Handle subdomains
RewriteCond %{SERVER_NAME} ^([a-z0-9-]+)\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/%1/$1 [L]
2 Likes

Hi @ajnyga

Do you know what the directives would be if there are multiple domains on the OJS installation

for example, we have https://journals.assaf.org.za/ as a the main domain, and there are journals as subs under it, like: Journal of Energy in Southern Africa whereas one of the journals has its own domain: https://www.sajs.co.za/

SAJS does not seem to have the issue of the api submissions error, but the other do.

Thanks,

Michael

Hi all,

Here I use this:

RewriteEngine on
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

(back-up it before do that)
After configure, inside cache folder:
rm *.php -rf
rm *.css -rf

Clear browser cache, in chrome you can use shit+f5 to force reload everything. In firefox I guess you can use ctrl+f5

Regards,
Tarcisio Pereira.

Hi all
I had the same problem and I struggled to manage to create a redirect/rewrite roles in the htaccess file.

I found out that I had a configuration issue in the server and htaccess was overwritten by server configuration.
Here are two potential solution:

Hope this can help

Thanks

1 Like

This worked for me!
But I can access my page with both url ie http://localhost/ojs/test-journal and http://localhost/ojs/index.php/test-journal

I want the 2nd url to be reidrected to the first or for that matter any url with index.php to be redirected to the one without index.php

Thanks