Custom domain, 443 settings, 404 ERROR page

Dear PKP users and developers

We have moved a custom domain (journal-name.domain.com) to a multi-journal OJS (with base-domain: base-site.com). We have followed the instructions in:

However these instructions did not say anything about how to set up apache for port 443. The thing that solved our problem was to define the DirectoryIndex in Apache’s 443 conf-file.

We used the following Apache-conf-file for port 443 and journal-name.domain.com:

<VirtualHost *:443>
ServerName journal-name.domain.com
DocumentRoot "/var/www/html/"
<Directory /var/www/html>
   AllowOverride All
   Options Indexes FollowSymLinks MultiViews
   Require all granted
   DirectoryIndex index.php/journal-name**
</Directory>
...
#logging and SSL settings
...
</VirtualHost>

We are using the following for port 80 and journal-name.domain.com

<VirtualHost *:80>
ServerName journal-name.domain.com
DocumentRoot "/var/www/html/"
<Directory "/var/www/html/">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
      Require all granted
</Directory>
...
#logging settings
...
</VirtualHost>

This is the apache-conf file for port 443 and main-site.com:

<VirtualHost *:443>
ServerName main-site.com
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
   AllowOverride ALL
   Require all granted
   DirectoryIndex index.php
</Directory>
## Logging
ErrorLog "logfile_error_ssl.log"
ServerSignature Off
CustomLog "logfile.log" combined
## Header rules
  Header Set Strict-Transport-Security "max-age=31536000"
## SSL directives
...
</VirtualHost>

This is the apache-conf file for port 80 and main-site.com:

<VirtualHost *:80>
ServerName main-site.com
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Require all granted
</Directory>
  ## Logging
  ErrorLog "logfile_error.log"
  ServerSignature Off
  CustomLog "logfile.log" combined
</VirtualHost>

Finally, this is our .htaccess file to set up restful_urls :

 RewriteEngine on
 RewriteCond %{HTTP_HOST} main\.server\.name\.com$ [NC]
 RewriteRule ^(.*)$ https://main-site.com/$1 [L,R=301]
 RewriteEngine On
 RewriteBase /

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

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

## Mainsite of OJS with journal overview
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^index/(.*)$ /index.php/index/$1 [QSA,L]
 RewriteEngine on
 RewriteCond %{REQUEST_URI} !=/server-status
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteEngine On
RewriteRule   ^/not_found_redirect/  http://journal-name.domain.com%{REDIRECT_REQUEST_URI}  [R,L]
  1. Does this setup look “correct”?

  2. We have a problem: We can not set up a custom error page for 404 errors. We have tried to add ErrorDocument 404 /404-file.html to the apache conf-files and to .htaccess files. The only thing that seems to work is to use: AllowOverride None. However, when using that command the rest of the site is broken!

  3. Another issue with this setup is that I need to log in twice in the backend when swithing from a jounral in domain1 to a journal in domain2. Is it possible to solve that?

We are using CentOS with Apache/2.4.6
PHP 7.1.17
OJS 3.1.1.4

The DirectoryIndex directive should probably read DirectoryIndex index.php rather than DirectoryIndex index.php/journal-name**. The DirectoryIndex directive tell Apache what to do when a user requests a directory instead of a file. In this case, we’re telling Apache to use the index.php file.

You can move the directives from the .htacess file into the apache-conf file, if it makes management easier. (This will, for example, remove the need to reproduce RewriteCond directives based on the domain name.

As configured, OJS will be handling any non-file, non-directory requests, which leaves OJS to handle the 404s instead of Apache. Setting AllowOverride None disables any .htaccess processing, which disabled OJS’s handling of URLs, which allows your ErrorDocument directive to be processed by Apache.

Logins are based on HTTP session cookies, and HTTP session cookies are based on domain. It is possible to move a session cookie up to a parent domain (so a cookie for server.tld is available at my.server.tld and www.server.tld and server.tld), but with different domains new logins will be required. The general solution to this is federated authentication, such as Shibboleth.

Dear @ctgraham,

Thank you for your reply!

We found that we can set up the 404-error handling in OJS here: lib/pkp/classes/core/Dispatcher.inc.php . We changed to these commands in function handle404()

 PKPRequest::_checkThis();
 header('HTTP/1.0 404 Not Found');
 readfile('404.html');
  1. this procedure insert the 404.html file twice - i.e. you get the message twice on the screen, like this:

404 error: file not found, redirecting to main site

404 error: file not found, redirecting to main site

  1. we want to have different messages for main-site.com and journal-name.domain.com. How can that be set up?

If you add a die() command after the readfile(), do you get only one instance of 404.html? I wonder if Apache is able to hook the 404 header produced by OJS (provided that PHP does not trigger an error. This could explain the duplicate message: once for the readfile(), and once for your ErrorDocument directive.

If that is the case, you can remove the readfile() directive (and the added die()) from the OJS code, and allow different ErrorDocument directives to take effect based on the Apache virtualhost.