Each journal with its own domain name

Hi,

At the University Of Bordeaux, we hosted several journals and we would like that each journal has its own domain name.

The main page of the plateform will be for example http://main_plateform.u-bordeaux.fr and when we clic on the url of a specific journal for example http://journal1.eu we would like that it shows what it is on http://main_plateform.u-bordeaux.fr/index.php/journal1 but we don’t want to see the url http://main_plateform.u-bordeaux.fr/index.php/journal1

I tried to create a virtualhost in Apache with the domain name journal1.eu with this documentroot: /var/www/ojs/index.php/journal1
It works but all the other links related to the css, js, etc are wrong because they are not located in the url base of the documentroot

Do you know how I can manage to do that ?

Thank you in advance for your answer.
Helene

1 Like

Have you set your base_url[]'s in config.inc.php per journal?

Hi,

Yes, I set the base_url[]'s in config.inc.php per journal.

In Apache: documentroot for the main platform: /var/www/ojs
In Apache: documentroot for domain name journal1.eu: /var/www/ojs/index.php/journal1
In Apache: documentroot for domain name journal2.eu: /var/www/ojs/index.php/journal2

In config.inc.php:
base_url[index] = http://main_plateform.u-bordeaux.fr
base_url[journal1] = http://journal1.eu
base_url[journal2] = http://journal2.eu

But it doesn’t work. It can’t find for example http://journal1.eu/lib/pkp/styles/pkp.css

Maybe, it’s not the proper way to do it.
Any advice or any clue ?

Thanks in advance.
Helene

The document root points the webserver, for a particular virtualhost, to where content should be served. For each virtual host which is serving OJS content, this should be your OJS install directory. In your case, each should be /var/www/ojs/ .

Thanks again for your answer.
if each each virtual host points to /var/www/ojs/
for example in Apache: documentroot for domain name journal1.eu: /var/www/ojs
When I clic on http://journal1.eu, I get the main page OJS platform with the list of all the journals and not the home page of journal “journal1”
How I manage to get the home page of journal “journal1” also available on http://main_plateform.u-bordeaux.fr/index.php/journal1 when I clic on http://journal1.eu ?

Thanks again.
Helene

Each virtualhost will also need a rewrite rule to route requests into the desired journal.

The general idea is:

  • Apache receives the request for “journal1” on the virtualhost for “journal1.eu”
  • The virtualhost for “journal1.eu” uses OJS as the document root
  • The virtualhost for “journal1.eu” redirects all requests to index.php/journal1/…
  • OJS picks up the request for index.php/journal1 and maps it to journal1.eu via the base_url[journal1]

You can find a in-depth discussion on the old forum:
https://pkp.sfu.ca/support/forum/viewtopic.php?f=2&t=2616

Hi,

First of all I wish to everybody a happy new year.

I almost solved my problem

  1. I configured on Apache virtualhost for “journal1.eu” to use OJS as the document root
  2. I configured file config.inc.php to set base_url[journal1] = http://journal1.eu
  3. I created an .htaccess file in OJS document root and wrote some rewrite rules by following this example:
    https://pkp.sfu.ca/support/forum/viewtopic.php?f=8&t=7578&start=30#p46079

http://journal1.eu displays well the home page of journal journal1. All URLs work fine: http://journal1.eu/about, http://journal1.eu/login, http://journal1.eu//user/register, etc except for the URL http://journal1.eu/index with the message “The requested URL /index was not found on this server.” and I don’t understand why ?

Is there an internal rewrite rule which could explain that ?

Thank you in advance for your answer.
Helene

1 Like

Can you post your rewrite rules here?

Here are my rewrite rules:

RewriteRule ^journal1/(.*)$ index.php/journal1/$1 [L,QSA]

RewriteCond %{SERVER_NAME} ^journal1.eu
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ journal1/$1 [L]

I tried to add others rewrite rules without any changes like those one:
RewriteRule ^journal1$ journal1/

RewriteRule ^journal1/(.)$ ojsDocumentRoot/index.php/journal1/$1 [L,QSA]
RewriteRule ^ojsDocumentRoot/journal1/(.
)$ ojsDocumentRoot/index.php/journal1/$1 [L,QSA]

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

1 Like

Your current rules say:

RewriteRule ^journal1/(.*)$ index.php/journal1/$1 [L,QSA]

If the path begins with “journal1/”, append anything that follows it to “index.php/journal1/”.

and

RewriteCond %{SERVER_NAME} ^journal1.eu
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ journal1/$1 [L]

If the server’s name begins with “journal1.eu” and the path doesn’t match a filename, send the request to “journal1/”. I can see why that might work, but also why it might be brittle.

Here is an example set of rules that I have working for us, FWIW:

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

    # if the incoming request references the journal shortname, use an external redirect to strip the journal shortname
    RewriteRule ^/JOURNALNAME/(.*)$ /$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}ojs%{REQUEST_URI} !-d
    # Ignore if request is for a known OJS file (Apache 2.2+)
    RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} !-f
    # Ignore if request is for a known OJS directory (Apache < 2.2)
    RewriteCond %{REQUEST_FILENAME} !-d
    # Ignore if request is for a known OJS file (Apache < 2.2)
    RewriteCond %{REQUEST_FILENAME} !-f
    # Otherwise, rewrite all requests through index.php to this specific journal shortname
    RewriteRule ^(.*)$ /ojs/index.php/JOURNALNAME/$1 [QSA,L]

    # Check if this request is for a static OJS file, but is missing the OJS prefix
    RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} -f
    RewriteRule ^(.*)$ /ojs/$1 [QSA,L]

This assumes that the ojs install is under a directory named “ojs” under the document root.

It also assumes it is applied at the name-based virtualhost level, where the virtualhost is listening for “my.domain-name.tld” via ServerName my.domain-name.tld.

It has been a while since I looked at the rewrite rules in depth, and there may be improvements which are possible. I had done some extensive testing on this formerly, with notes here: https://pkp.sfu.ca/bugzilla/show_bug.cgi?id=8797#c16 .

2 Likes

I also try to realize different journal names in on OJS instance but with no success so far. I also read the linked old threads and tried a lot with different document roots for the apache virtual hosts, different settings in the config.inc.php and different .htaccess rules.

Can someone with a working configuration post the apache document roots, the config.inc.php settings and the according .htaccess rewrite rules?

One possible approach could be as simple as:

Apache VirtualHosts with:

DocumentRoot /var/www/html

ServerName JOURNALNAME.host.name

(with rewrite rules as a specified above)

The config.inc.php base_url’s could look like:

base_url http://journals.host.name/

base_url[index] = http://journals.host.name/index
base_url[JOURNALNAME] = http://JOURNALNAME.host.name

It would probably be helpful to describe what you have configured currently, and what specifically is not working in that configuration. Since server configurations vary so widely, it is easier to troubleshoot a specific instance than it is to provide a sample that will be guaranteed to work everywhere.

@ctgraham Our OJS productive environment is not live yet so we can still modify the configuration. I’m testing the journal domain name rewriting in an ubuntu 16.04.1 virtual box and modify my windows host file to resolve the test-domains.

The ubuntu apache has the following 000-default.conf

<VirtualHost *:80>
	<Directory /var/www/html>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
	ServerName journals.uni-giessen.de
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

There are two other virtual hosts enabled with servername test1.domain and servername test2.domain. Both have the same document root /var/www/html.

OJS 3.0.1 is installed /var/www/html/ojs and i created two journals with the path test1 and test2. Without any rewrite setting i can easily access them.

The relevant lines from OJS config.inc.php

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

In the OJS root directory /var/www/html/ojs there is a .htaccess file with the following adapted rewriting rules:

# hcgraham solution
RewriteEngine on
RewriteRule ^/(index.php)?/?$ /ojs/index.php/test1/index [L]

RewriteRule ^/test1/(.*)$ /$1 [R,L]
RewriteCond %{REQUEST_URI} !/index.php/
RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /ojs/index.php/test1/$1 [QSA,L]

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

Ubuntu 16.04.1 is using Apache 2.4 so i commented out the {REQUEST_FILENAME} lines.

I can access http://journals.uni-giessen.de/ojs and http://test1.domain/ojs. Both display to the starting page of the Test1 Journal. Accessing http://test1.domain leads to the standard Ubuntu apache starting page in /var/www/html

It seems some style elements are applied but e.g. the magnifying glass in the search line is missing, the symbols at the PDF-Buttons are broken as well as the OJS-symbol in the footer:

There should also be a journal specific CSS-file changing the background color which is not applied. If you login as journals manager, many functions/links (like “My Queue” in Tasks etc.) in the backend are broken.

Our requirement is the same as described by @hcl

Try putting the rewrite rules in your Apache VirtualHosts instead of in the .htaccess file. The rules will vary from vhost to vhost… for example, test1.domain redirecting to test1, test2.domain redirecting to test2, and jorunals.uni-giessen.de not redirecting to a specific subpath.

So I didn’t uncomment the lines in config.inc.php but had these rules in my virtual hosts entry:

    RewriteCond %{REQUEST_URI} !^/index/user [NC]
    RewriteCond %{REQUEST_URI} !^/index\.php/* [NC]
    RewriteCond %{REQUEST_URI} !^/lib/pkp/styles [NC]
    RewriteCond %{REQUEST_URI} !^/styles [NC]
    RewriteCond %{REQUEST_URI} !^/public/journals [NC]
    RewriteRule ^(.*) http://CUSTOMDOMAIN/index.php/JOURNALNAME$1 [NC]

It seems to work but is there an issue with how I’ve done it?

@tauyeung, what is the larger context of this rewrite rule?

It essentially says, any request which doesn’t match any of the specified URIs be redirected to an absolute URL. I’m not sure why you’ve selected the conditions you’ve selected.

Our setup is that we have a master domain for hosting journals and some but not all of the journals have completely independent domains and we’re hosting it all in a single instance of OJS. When I started doing this, I used journal domain settings in config.inc.php and the rewrite rules you posted to the forum as my starting point but that didn’t work (for whatever reason).

This set of rules sits in the virtual host entry for the custom domain with no settings in the config file.

My only caution would be that is seems odd to me to be forcing a redirect to an absolute, fully-qualified domain name URL.

There are myriads of ways to configure mod_rewrite, however, and the details can quickly verge outside of the scope of this forum, so the important thing is whether it is working for you.

Just be sure that you are not inadvertently mixing HTTP requests of some content from http://my.maindomain/ and http://a.customdomain/ in the same request - that is sure to cause confusion.

I deleted the .htaccess-file in the ojs-directory and moved the rewrite rules to the virtual hosts config file, e.g. test1.conf

<VirtualHost *:80>
	<Directory /var/www/html>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
	ServerName test1.domain 
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/test1-error.log
	CustomLog ${APACHE_LOG_DIR}/test1-access.log combined
	RewriteEngine on
	RewriteRule ^/(index.php)?/?$ /ojs/index.php/test1/index [L]
	RewriteRule ^/test1/(.*)$ /$1 [R,L]
	RewriteCond %{REQUEST_URI} !/index.php/
	RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} !-d
	RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} !-f
	#RewriteCond %{REQUEST_FILENAME} !-d
	#RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ /ojs/index.php/test1/$1 [QSA,L]
	RewriteCond %{DOCUMENT_ROOT}ojs%{REQUEST_URI} -f
	RewriteRule ^(.*)$ /ojs/$1 [QSA,L]
</VirtualHost>

After an apache restart i get the starting page of the journal by accessing test.domain. But no css-styles seem to have been applied.

The links on this page go to e.g. http://test1.domain/ojs/article/view/99 (for an article view) and result in a 404-error. If i access journals.uni-giessen.de i get the OJS-overview site with the list of available journals but also no styles have been applied

@tauyeung That is exactly our goal at least for one of the journals. Can you please send me your configuration (virtual hosts, config.inc.php and your rewrite rules)?

Is OJS installed in the /var/www/html directory, or in an “ojs” folder under /var/www/html ?