Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Apache ErrorDocument 404 but without the automatic 404 header?

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #37487
    D3mon
    Member

    I’m trying to get my 404 document to check the DB to generate a page if the URL provided is listed there, but the server seems to send out a 404 header before I get a chance (in the 404 script) to send a 200 (if there is a matching page reference in the database – how can I prevent this?

    #100572
    D3mon
    Member

    My 404 psuedocode:


    1. get URL
    2. Check URL in Database
    3. If it exists:
    Send 200 header and output DB-driven HTML
    If not:
    Send 404 header and output error HTML
    #100573
    D3mon
    Member

    Problem is that Apache sends the 404 header BEFORE it runs my 404 script.

    #100580
    D3mon
    Member

    OK, but the idea here is that my pages are entirely database driven and don’t have actual files in the webspace. Do you see what I mean?

    #100588
    D3mon
    Member

    I’m not sure I have acces to the httpd.conf as this project is on shared hosting, even the the.htaccess is locked down to a few ‘allowed’ options.

    If I change to a static 404 page, how will I get the server to execute the index.php (in the webroot?) that will generate the page if the client requested URI is http://www.examplesite.com/exampleproduct/index.php (which, of course, won’t actually exist?)

    #100624
    D3mon
    Member

    Got it! (finally)

    In my .htaccess file, instead of using:

    ErrorDocument 404 /error/

    I used:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /error/

    to execute the error script in the event a requested file or folder could not be found. The benefit of this being that no header is sent and you can then decide in that script which header you want to send and what to display (based on page info you might have in the DB etc.)

    #100664
    D3mon
    Member

    If the page URL doesn’t exist in the DB, then the script responds with a 404 header and custom 404 HTML (not CMS driven).

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.