OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



custom error pages

Are you responsible for making OJS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
What to do if you have a technical problem with OJS:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a development question, try the OJS Development subforum.

custom error pages

Postby imtechnology » Mon Jul 09, 2012 4:46 am

Hi All!

I am trying to implement custom error pages through the .htaccess file.

However, it seems that the internal error handling system is overriding the .htaccess settings.

instead of my custome error page all i get is a page whose source code contains:
Code: Select all
<h1>404 Not Found</h1>


Can anyone advise if it is possible to have custom error pages?

I've included a copy of my .htaccess file incase I've made an error in it.

Many Thanks!

Ed.

Code: Select all
ErrorDocument 400 /400.shtml
ErrorDocument 401 /401.shtml
ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml

php_flag apc.cache_by_default Off

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mainsite.com.au
RewriteRule (.*) http://www.mainsite.com.au/$1 [R=301,L]

# Use this set of 3 lines for each of your journals
RewriteCond %{SERVER_NAME} ^journal1.com.au
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/journal1/$1 [L]

# Use this set of 3 lines for each of your journals
RewriteCond %{SERVER_NAME} ^www.journal1.com.au
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/journal1/$1 [L]

# Use this set of 3 lines to allow access to the site level
RewriteCond %{SERVER_NAME} ^mainsite.com.au
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/index/$1 [L]

# Use this set of 3 lines to allow access to the site level
RewriteCond %{SERVER_NAME} ^www.mainsite.com.au
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/index/$1 [L]
imtechnology
 
Posts: 13
Joined: Sat Jun 23, 2012 6:46 pm

Re: custom error pages

Postby asmecher » Mon Jul 09, 2012 12:18 pm

Hi Ed,

OJS provides its own 404 page; see lib/pkp/classes/core/Dispatcher.inc.php and look for the handle404 function. If you like, you could alter that to redirect to your custom 404 page (or you could include it directly from within the PHP script).

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8479
Joined: Wed Aug 10, 2005 12:56 pm

Re: custom error pages

Postby imtechnology » Tue Jul 10, 2012 3:23 am

Hi Alec!

Thanks for the advice. Unfortunately I couldn't work out how to redirect to a custom error page while still providing a 404 response code for search engines.

So after a bit of searching around I came up with this. Its not exactly the best solution but it works for me and gives users the opportunity to search for the content that they are looking for.

Go to /lib/pkp/includes/functions.inc.php

replace:

Code: Select all
   echo "<h1>$reason</h1>";


with this:
Code: Select all
// ERL error meta refresh
//   echo "<h1>$reason</h1>";

   echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">";
   echo "<HTML><HEAD>";
   echo "<TITLE>404 Not Found</TITLE>";
   echo "<meta http-equiv=\"refresh\" content=\"1;url=/search\">";
   echo "</HEAD><BODY>";
   echo "<h1>$reason</h1>";
   echo "The requested URL was not found on this server.";
   echo "<HR>";
   echo "</BODY></HTML>";


This displays the error (with the appropriate 404 header for search bots) for a second to the users and then redirects the page to the search page.

Alec,

is there a way we can add a parameter to the config.inc.php to enable or disable this facility?
any chance something like this could go into the next version?

Cheers and thanks again for your help!

Ed.
imtechnology
 
Posts: 13
Joined: Sat Jun 23, 2012 6:46 pm

Re: custom error pages

Postby imtechnology » Tue Jul 10, 2012 3:52 am

I've just realised that the generated page does not meet the requirements for internet explorer to display it because the total size was less than 512 bytes.

so an alternative to the code I posted previously could be:

Code: Select all
//ERL error meta refresh
//   echo "<h1>$reason</h1>";

   echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">";
   echo "<HTML><HEAD>
   <TITLE>$reason</TITLE>
   <meta http-equiv=\"refresh\" content=\"1;url=/search\">
   </HEAD><BODY>";
   echo "<h1>$reason</h1>";
   echo "<div><b>In a moment or two you will be redirected to the websites search page.</b> <br />If this does not occur try clicking <a href=\"/search\" title=\"Search Page\">this link</a>.<br /><br /></div>
         <div>Search tips:
         <ul>
            <li>Search terms are case-insensitive</li>
            <li>Common words are ignored</li>
            <li>By default only articles containing <em>all</em> terms in the query are returned (i.e., <em>AND</em> is implied)</li>
            <li>Combine multiple words with <em>OR</em> to find articles containing either term; e.g., <em>education OR research</em></li>
            <li>Use parentheses to create more complex queries; e.g., <em>archive ((journal OR conference) NOT theses)</em></li>
            <li>Search for an exact phrase by putting it in quotes; e.g., <em>\"open access publishing\"</em></li>
            <li>Exclude a word by prefixing it with <strong>-</strong> or <em>NOT</em>; e.g. <em>online -politics</em> or <em>online NOT politics</em></li>
            <li>Use <strong>*</strong> in a term as a wildcard to match any sequence of characters; e.g., <em>soci* morality</em> would match documents containing \"sociological\" or \"societal\"</li>
         </ul>
   <HR>
   </BODY></HTML>";
imtechnology
 
Posts: 13
Joined: Sat Jun 23, 2012 6:46 pm

Re: custom error pages

Postby asmecher » Tue Jul 10, 2012 2:58 pm

Hi Ed,

That's your error message handler, not your 404 landing page... What is the $reason that you're seeing when you land there?

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8479
Joined: Wed Aug 10, 2005 12:56 pm

Re: custom error pages

Postby piotreba » Wed Apr 16, 2014 1:39 pm

This is handy topic, and could someone suggest how to modify handle404 function in Dispatcher.inc.php in order to redirect to custom error page?
piotreba
 
Posts: 151
Joined: Mon Dec 13, 2010 3:29 pm

Re: custom error pages

Postby asmecher » Wed Apr 16, 2014 2:05 pm

Hi piotreba,

You could do something like...
Code: Select all
header('Location: /path/to/my/404.html');
exit();
Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8479
Joined: Wed Aug 10, 2005 12:56 pm


Return to OJS Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests