Each journal with its own domain name

The Apache is 2.4 but the %{REQUEST_FILENAME} variable seem to work fine.

I tried a fresh approach using a config from a colleague and i nearly got it. The apache vhosts point to:

ServerName = journals.uni-giessen.de document_root = /var/www/html/ojs

These are the relevant lines of config.inc.php

base_url = "http://journals.uni-giessen.de"
base_url[test1] = http://test1.domain
restful_urls = On

If moved the rewrite rules to a .htaccess file again

RewriteEngine On
## test1
RewriteCond %{SERVER_NAME} ^(www\.)?test1.domain
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/test1/$1 [QSA,L]
## test2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^test2(.*)$ /index.php/test2/$1 [QSA,L]

Accessing test1.domain shows the test1 starting page. All the style files seem to have been applied. You can access articles and also the journal backend. The only noticeable effect is that some symbols like the magnifying glass in the search bar oder the PDF-symbols in the fulltextbuttons seem to be broken:

And on the ojs journal index page which lists all available journals the css-style style is not applied so it looks blank. I checked in the site source code and the link to the css results in an 404-error

href="http://journals.uni-giessen.de/index/$$$call$$$/page/page/css?name=stylesheet

The link should be:

href="http://journals.uni-giessen.de/index.php/index/$$$call$$$/page/page/css?name=stylesheet"

Accessing the test2 journal on the main page via http://journals.uni-giessen.de/test2 has no flaws so far. The index.php is removed from the address, all styles are found and also the icons that are broken on the test1-journal work here.

Has anyone ideas for the remaining problems?

With “restful_urls” on, all URLs will be output without the index.php component for the site. Because of that, you’ll need an additional mod_rewrite rule to rewrite URLs of the form “^/index/(.*)” to /index.php/index/$1.

See this thread for cross-origin considerations in displaying the glyphicons:

I added the following rule at the end of the .htaccess file:

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

At first it didn’t work. But after creating an empty folder on the filesystem level /var/www/html/ojs/index everything is fine. And the glyphicons also have recovered (magically).

Thank you for the support.

Dear florianruckelshausen,

It seems you are finally successful to set each journal with its own domain name.
I read the long story, but still don’t find a way to follow your method. Could you summary your method in a documentation? I think it will help a lot of people like me.
Thank you in advance

Best regards

See also @ajnyga’s post here:

@Buyi_Li
Here is my mini HOWTO for configuring different domain names in a single OJS installation. They have been tested on Ubuntu 16.0.4 and a recent Open Suse, both running Apache 2.4.
Goal: You have a main journal platform (journals.uni-giessen.de) with some journals. The index.php in the URL should be stripped from all journals. Some of your journals are fine with staying on your main journal page. Others want to have their own domain (rmm-journal.de).

OJS is installed in /var/www/html/ojs

  • Activate the apache rewrite mod
  • Set up you apache hosts
    For the main journal platform:
<VirtualHost *:80>
	<Directory /var/www/html/ojs>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
	ServerName journals.uni-giessen.de
	DocumentRoot /var/www/html/ojs
</VirtualHost>

For the journal that wants its own domain:

<VirtualHost *:80>
	<Directory /var/www/html/ojs>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
	ServerName rmm-journal.de
	DocumentRoot /var/www/html/ojs
</VirtualHost>

The options in in directory clause are important. You also have to consider the servernames with www and port 443 configuration. For better overview i stripped this from the example

RewriteEngine On
RewriteBase /
## RMM has its own domain
RewriteCond %{SERVER_NAME} ^(www\.)?rmm-journal.de
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/rmm/$1 [QSA,L]
## test2 just index.php stripping
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^test2(.*)$ /index.php/test2/$1 [QSA,L]
## Mainsite of OJS with journal overview
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/(.*)$ /index.php/index/$1 [QSA,L]

I didn’t use RewriteCond %{REQUEST_FILENAME} !-d because it made some trouble and it seems to work without it.

  • Set up OJS config.inc.php. Here are the relevant lines that worked for me
base_url = "http://journals.uni-giessen.de"
...
base_url[index] = http://journals.uni-giessen.de/index
base_url[rmm] = http://rmm-journal.de
base_url[test2] = http://journals.uni-giessen.de/test2
...
restful_urls = On
  • Create an empty directory “index” in the ojs directory on the filesystem level /var/www/html/ojs/index I had to do this so that the OJS mainsite (with all the journals available on this ojs installation) works well with the rewrite rule.

Our OJS in not live yet but so far everything seems to be fine this way.

7 Likes

Congratulations @florianruckelshausen,

Thank you very much for sharing this with us!

Can you please take a bit of time, and add a bit of documentation to: OJS Documentation Wiki?

This is a very often asked question and your directions would be very useful to the community.

Regards

This worked for us also although rather than catching the individual journals and redirecting to sub directories we used the existing catch all.

We have all but one journal on http://journals.knowledgearc.com/, so http://journals.knowledgearc.com/journal1, http://journals.knowledgearc.com/journal2, etc. However, one of our journals, journal3, is on a completely different domain, I.e. http://completely.different.domain. So we used the following in htaccess:

RewriteEngine On
RewriteBase /
## journal3
RewriteCond %{SERVER_NAME} ^completely.different.domain
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/journal3/$1 [QSA,L]
## All other journals
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

The first checks for completely.different.domain and redirects to journal3. All other journals just get sent to http://journals.knowledgearc.com.

In config.inc.php

base_url[journal3] = http://completely.different.domain

we didn’t need to set base_url[index].

1 Like

Watch out how your journal statistics start to work. We noticed that with when we had a subdomain defined for journal1 and an ordinary domain for journal2, it was not enough to define base_url[journal1]. We also had to define base_url[journal2] and set the default journal url there. See Usage stats warnings: system can't remove the base url

So does this mean if you have, say 5 journals, journal[1-5] and journal1 is on a different domain but all others are on the same domain you still need to set up 5 base_url[journal[1-5]]?

Basically yes, when you are using a single installation of OJS.

In our case if I have site.com/journal1 and journal2.site.com, I have to define both although only journal2 has a special url:
base_url[journal1] = http://site.com/journal1
base_url[journal2] = http://journal2.site.com

This of course comes a bit annoying when you have a lot of journals (we have around 60).

But I suggest that you test what happens in your case. Just see if all your journals get statistics after defining that one special base_url.

Hi,

We are using OJS31, 3.1.0-1 exactly.

We host several journals with their own domain name.

So we have an “.htacess” file with RewriteRule directives like this:

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

RewriteCond %{SERVER_NAME} ^(www.)?journal2.org
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/journal2/$1 [QSA,L]

And here is an example of our “config.inc.php” file:

base_url = "https://openhomeportal.org/journals"
disable_path_info = Off
allow_url_fopen = Off
base_url[journal1] = https://journal1.org
base_url[journal2] = https://journal2.org
restful_urls = Off

And here is a part of our Apache (2.4) config file for portal home page:

ServerName journalsportal.org
DocumentRoot /var/www/

(we have other content that journals under URL openhomeportal.org.org)

And here is a part of our Apache (2.4) config file for a specific journal with its own domaine name:

ServerName journal1.org
DocumentRoot /var/www/journals

Those URL work fine:
Home page of OJS portal: https://openhomeportal.org/journals: display the home page of OJS journal with the list of all journals
Journal1: https://journal1.org: display the home page of Journal1
Journal2: https://journal2.org: display the home page of Journal2

But there is big mismatch between URL:
At first, https://journal1.org/index.php or https://journal2.org/index.php display content of Home page of OJS portal (https://openhomeportal.org/journals) instead of content of journal home page.
But the biggest problem is https://journal1.org/index.php/journal2 display content of journal2 and https://journal2.org/index.php/journal1 display content of journal1
So google references articles of journal2 inside the journal1 and vice versa.
It’s very detrimental for journals.
I tested many possibilities of configuration in “.htacess” file with RewriteRule directives but nothing work to prevent URL https://journal1.org/index.php to display content of Home page of OJS portal (https://openhomeportal.org/journals) instead of content of journal home page and so on https://journal1.org/index.php/journal2 to display content of journal2.

I would be very grateful for your help.
Thanks in advance.
Best regards.
Helene

1 Like

Unfortunately, to prevent this, you will need to add re-write conditions to exclude each URL form which you want to block. If you were using RESTful URLs, you might be able to simply block direct access to index.php so that all traffic would have to go through your approved re-writes. Barring that, you will need an additional rule to check something like:

  • is the SERVER_NAME not journal1.org
  • does the REQUEST_FILENAME include /index.php/journal1
  • Rewrite to 404
1 Like

Hi @ctgraham,

Thanks a lot for your swift reply!

I added an additional rule in “htaccess” file:

RewriteCond %{SERVER_NAME} ^(www.)?journal1.org
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.)$ /index.php/journal1/$1 [QSA,L]
RewriteRule ^(.
)/journal2/(.*)$ /404 [L,R]

I thought it was working because URL https://journal1.org/index.php/journal2 was redirected to 404 but https://journal2.org/ isn’t working anymore.
Could you give me some help to write the proper RewriteRule ?

I also wanted to test to activate restful_urls in “config.inc.php” file.
But I doesn’t seem to block direct access to index.php :

Do I have to add other rules in “htaccess” file to make RESTful URLs work ?
What is the use of RESTful URLs except to block direct access to index.php ?

Thanks again for your precious help.
Kind regards.
Helene

1 Like

I have configured my OJS for multiple journals (only one at the moment) in OJS 2.4.8 with
base_url[JNAME] = http://JNAME.ucc.ie
and Apache as suggested, with a VH for the JNAME serving from /var/www/html/ojs and your rewrite rules (for which many thanks). I commented out the two conditions for Apache <2.2 as we’re on 2.2.15, and added three lines in their place:

# snag bogus references to /public, /plugins, /styles
RewriteRule ^/public/(.*)$ http://SERVER.ucc.ie/ojs/public/$1 [QSA,L]
RewriteRule ^/plugins/(.*)$ http://SERVER.ucc.ie/ojs/plugins/$1 [QSA,L]
RewriteRule ^/styles/(.*)$ http://SERVER.ucc.ie/ojs/styles/$1 [QSA,L]

It’s all working well except for a couple of URIs.

  1. If I log into JNAME with an author login, I correctly get the page http://JNAME.ucc.ie/user and it all looks fine, but the links behind “User Home” and “My Journals” both go to http://SERVER.ucc.ie/ojs/user which is 404. I assume this link ought to be http://JNAME.ucc.ie/user but I don’t know if this is due to some internal OJS config, or something I should trap in the rewrite rules (and I’m not clear how).
  2. The generated links fail on the Step 1 page for “Author Guidelines” (http://JNAME.ucc.ie/ojs/index.php/JNAME/about/submissions#authorGuidelines) [404] and “Ensuring a Blind Review” (javascript:openHelp(‘http://SERVER.ucc.ie/ojs/index.php/JNAME/help/view/editorial/topic/000044’)) [nothing happens although the embedded URI does work if pasted manually].
  3. If I log out and go to http://SERVER.ucc.ie/ojs I get the base home page but the login link goes to http://SERVER.ucc.ie/ojs/login/signIn which is 404, so I cannot sign in as admin to fix anything inside OJS!

I have obviously done something wrong, but what? I certainly used to be able to login as admin (ie the link worked) and I’m not aware of changing anything that would stop it. What is the real login URI?

P

@hcl, the purpose of the RESTful URLs is to remove index.php from the public presentation of the URL.

I don’t think the example you give functions the way you want.

RewriteCond %{SERVER_NAME} ^(www.)?journal1.org
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.)$ /index.php/journal1/$1 [QSA,L]
RewriteRule ^(.)/journal2/(.*)$ /404 [L,R]

This ties two Rewrite Conditions to the first Rewrite Rule, and leaves the second RewriteRule with no Rewrite Conditions. I think you want the second Rewrite Rule to be conditional on the SERVER_NAME of journal1.org as well (unless this is a final catch-all after all journal-specific traffic has been handled).

@Peter_Flynn,

In an install which uses the /ojs/ subdirectory, I do have an additional rule to catch static file access:

    RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} -f
    RewriteRule ^(.*)$ /ojs/$1 [QSA,L]

Regarding the user home, this is a longstanding difference of opinion within the project regarding whether the user home should direct to the Site, or whether the user home should direct to the current Journal. See:
https://pkp.sfu.ca/bugzilla/bugslist/show_bug.cgi?id=8802

The current 2.4.8 code tries to detect whether the user has access to multiple journals within the site, and send the user to the Site if that is the case:

I have preferred to always default to the Journal’s User Home:

Hi @ctgraham,

Could you give me please a suggestion of an additional RewriteRule that could work to check that:

  • is the SERVER_NAME not journal1.org
  • does the REQUEST_FILENAME include /index.php/journal1
  • Rewrite to 404

I tried several rules that do not work and I feel a bit stuck.

Thanks again for your precious help.
Kind regards.
Helene

Thanks very much. I agree it should default to the journal user’s home, not the OJS installation.
I’m not clear what to do with the extra rule, though. I should have made it clear that this server is serving dozens of applications, not just OJS, and right now, this journal is the only cname using Rewrite, so all the rules are inside the Apache VH block for that cname.

To my mind, as the problem arises with http://SERVER.ucc.ie/ojs/user, not http://JNAME.ucc.ie/ojs/user, I would need to add this rule at the top level of httpd.conf, outside any virtual host blocks, and it could then be hardwired to catch this specific instance…which of course won’t work when there are multiple journals, because how will it know which one to go to when there is no trace of a journal name in the incoming URI?

By the phrase, “the extra rule”, do you mean:

    RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} -f
    RewriteRule ^(.*)$ /ojs/$1 [QSA,L]

?

If so, since this rule targets only static files and is not journal specific, it should work anywhere. It essentially says:

  • If a request matches a file in the /ojs/ directory under the document root
  • Map the request to that file