Each journal with its own domain name

@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

An example rule might be:

RewriteCond %{SERVER_NAME} !^(www.)?journal2.org
RewriteRule ^index.php/journal2/ - [L,F]

(not actually tested)

Hi @ctgraham,

The RewriteRule works. I just made a tiny change like this:
RewriteRule ^index.php/journal2(.*)$ - [L,F]

I would like now to take a closer look to us restful_urls option.

Thanks a lot, it was very helpful.
Kind regards.
Helene

I’m tearing my hair out here in frustration. Thanks for your tips on getting a custom-subdomain-per-journal working, that seems to be fine. What is not fine is that no-one else can login, only users of the subdomain-named journal. Users who want to log in at plain /ojs/ get a 404 when they click Login

Demo: If you go to http://sulis.ucc.ie/ojs/ and try to log in as user foo with password bar, you get a 404 The requested URL /ojs/login/signIn was not found on this server.

Can anyone suggest why? Where is that click on Login supposed to go to?

In the URL /ojs/login/signIn, /ojs would be your OJS root location which contain index.php. You’ll need a rewrite rule that maps “login/signIn” following “index.php/index/”. The second “index” reference there is for the site index, which would otherwise be the journal shortname.

Can you share your current rewrite rules?

Thanks for your swift response.
This is plain CentOS6 with plain Apache2. Lots of other virtual hosts, but OJS is in /var/www/html/ojs.
I’m not clear what “following” means in your suggestion. Do you mean

RewriteRule  index.php/index/  login/signIn

or are you implying that I should already have some other rule mentioning index.php/index and that a new one is to come on the line underneath? If so, what would the exact incantation be?

The only two lines in the config right now are these (and I only added them yesterday, from a suggestion I found on one of the web pages about rewrite problems in OJS, while trying to fix this).

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

The oddity is that it’s been working fine for a year, with users logging in without problems. No-one has updated anything (they can’t: I’m root, and I haven’t).

The URL /ojs/login/signIn should map to the script path of /ojs/index.php/index/login/signIn or /ojs/index.php/journalname/login/signIn. That is, a PATH_INFO passes to “index.php” parameters of:

  • context: “index” for the site level, or a journal path for the journal level
  • page: “login” for login/logout operations
  • operation: “signIn” for authenticating credentials

Is the sulis subdomain specific to a single journal, or does this represent your OJS site-admin level?

If I add Redirect /ojs/login/signIn http://sulis.ucc.ie/ojs/index.php/index/login/signIn to httpd.conf it then honours a click on the login button, but then it tries to go to http://sulis.ucc.ie/ojs/user which fails.

That should presumably be redirected to somewhere else, by the same logic http://sulis.ucc.ie/index.php/index/user but that doesn’t work.

Is there a list of all the redirects/rewrites I am going to need?

On the sulis subdomain /ojs/ is the site-level admin. Journals will have their own virtual host, eg the working one, http://aigne.ucc.ie/ with the block of rewrites that you composed the last time I got stuck, which seem to be working fine apart from the argument about where ‘Home’ should go.

P

You don’t want to maintain a set of rewrites for each page and operation. The general form of the URL will be:
protocol :// domain / baseurl / index.php / context / page / operation

You can mask one or both of index.php and context via re-write rules, if desired.

For sulis.ucc.ie to be your site index, and for the URL not to contain the second context reference to “index”, you’ll want your rewrite rule to say something like:

# For any request which is directed to sulis
RewriteCond %{SERVER_NAME} ^sulis.ucc.ie
# If the request does not already map to a filename
RewriteCond %{REQUEST_FILENAME} !-f
# take anything after /ojs/ and append it as the page and op of the index context for OJS's index.php
RewriteRule ^/ojs/(.)$ /ojs/index.php/index/$1 [QSA,L]

This will require a config.inc.php entry of:

base_url[index] = http://sulis.ucc.ie/ojs

Alternately, if you don’t mind seeing the “index” context in the URL, the simpler (in my mind) configuration would be:

# For any request which is directed to sulis
RewriteCond %{SERVER_NAME} ^sulis.ucc.ie
# If the request does not already map to a filename
RewriteCond %{REQUEST_FILENAME} !-f
# take anything after /ojs/ and send it to OJS's index.php
RewriteRule ^/ojs/(.)$ /ojs/index.php/$1 [QSA,L]

With a config.inc.php base_url of:

base_url = http://sulis.ucc.ie/ojs

n.b.: all of this is off the top of my head and untested.

This is great, thanks. I wasn’t aware of that URI structure before.

The Apache picture is muddied by the fact that OJS isn’t the only thing in the top-level /var/www/html — there are dozens of other applications running there, each in its own subdirectory. But examining the RewriteRule it doesn’t look as if it will affect them.

So I applied that. The base_url was already there (I did then when installing OJS) along with the entry for the working journal.

So now when I go to http://sulis.ucc.ie/ojs it gives me my OJS Home page already, showing a Log Out link (presumably the login attempt the other day did actually work, even though it couldn’t get to the target URI).

But when I click on Log Out, I get a 404 for http://sulis.ucc.ie/ojs/login/signOut

This doesn’t seem to be being mapped by the RewriteRule.

What RewriteRule would I need to overcome this, and will there be others?

Anyone reading this?

Hello I’m try to configure our platform with 1 sub-domain per journal.

I follow your method but I get "No Access-Control-Allow-Origin header is present on the requested" error when editing users.

I’ve seen this topic but I can’t succeed how to modify my configuration properly

Can anyone help me ?

Here are my files

Apache hosts

   <VirtualHost *:80>
  ServerName www.dynrev-local.com
  DocumentRoot /var/www/html/ojs
  <Directory /var/www/html/ojs/>
    	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Require all denied
	Require all granted
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
  ServerName demo.dynrev-local.com
  DocumentRoot /var/www/html/ojs
  <Directory /var/www/html/ojs/>
    	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Require all denied
	Require all granted
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
  ServerName dynamic-reviews.dynrev-local.com
  DocumentRoot /var/www/html/ojs
  <Directory /var/www/html/ojs/>
    	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Require all denied
	Require all granted
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

.htacess

RewriteEngine On
RewriteBase /

## demo has its own domain
RewriteCond %{SERVER_NAME} ^(demo\.)?dynrev.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/demo/$1 [QSA,L]

## dynamic-reviews has its own domain
RewriteCond %{SERVER_NAME} ^(dynamic-reviews\.)?dynrev.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/dynamic-reviews/$1 [QSA,L]

## Mainsite of OJS with journal overview
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/(.*)$ /index.php/index/$1 [QSA,L]
1 Like

You have a discrepancy between your use of dynrev-local.com and dynrev.com, which may just be a transcription issue.

I’d recommend moving the Rewrite rules into your VirtualHosts. You will then not need the RewriteCond directives for each domain name, and your configuration will be much simpler.

Here is the stanza I use for this scenario:

Hi @ctgraham,

Is this feature available on OJS 3? Will it allow me to add a custom domain name for a journal?

Thanks!

Yes, this functionality remains the same in OJS 3.x as in OJS 2.x.

1 Like