• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Custom Error Doc With PHP or ASP

D

daveberk

Guest
Had to figure this out for my needs, thought I would share it with the community.

I wanted to use PHP (or ASP) to process "404 page not found" errors.

I added this JavaScript code to the <head> tag/area of the not_found.html file in the error_docs folder.

<SCRIPT LANGUAGE="JavaScript">
<!--
window.location="http://www.<mysite>/error-handler.php?req="+location.href;
// -->
</script>

Then I created my error-handler.php file (in the httpdocs folder) with this code:

@$page = $_GET['req'];

This loads the URL of the error-ed page into the $page variable (ex. http://www.<mysite>/bad-page.html).

The rest is up to you. I am using it to check a database for "subscriber aliases"
(ex. http://www.<mysite>/person1) that I then use to redirect the visitor to a certain page, also stored in the database.

Obviously it won't work for people with JavaScript turned off, but I tend to go with the 99% solutions.

Hope this helps.
 
Back
Top