Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:10:52+00:00 2026-05-25T21:10:52+00:00

I have a custom 404 error page, and a mod_rewrite rule. If I access

  • 0

I have a custom 404 error page, and a mod_rewrite rule. If I access a page that does not exist, I get my 404 error page. My problem is that if I issue a 404 header from my php page, it does not open my 404 page, instead, I get this:

Not Found

The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying
to use an ErrorDocument to handle the request.

This is my .htaccess:

RewriteEngine on
ErrorDocument 404 /errors/404.php
RewriteRule ^[A-Za-z0-9]{8}/$ /index.php

This is my redirect from /index.php that will 404 only if the key does not exist. The $key is obtained from parsing the URL (e.g. http://localhost/aKeYCoDE/):

<?php
if (!key_exists($key)){
    header('HTTP/1.0 404 Not Found');
    exit;
}
?>

I am expecting it to redirect to my 404 page.

UPDATE:

It is definitely something about the fact that I am calling 404 from a page that was rewritten (/index.php). If I create a dummy page: /redirect.php, and then do nothing but issue the 404 from there, I get my custom 404 page. But, if I write a mod_rewrite rule for it, and try to access it that way, I get the default 404 error page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:10:53+00:00Added an answer on May 25, 2026 at 9:10 pm

    I found the answer – the problem was my assumption that a header 404 from php would redirect to a 404 page. That was wrong. The Apache server can issue 404 for pages that do not exist, but for pages that do exist, i.e., are being served by the php page, the 404 response goes to the browser.

    This thread was of a similar issue:
    http://www.webmasterworld.com/forum88/10955.htm

    To make php do what I want it to do (issue the 404 when key does not exist), I need to include the 404 page from php:

    <?php
    if (!key_exists($key)){
        include($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
        exit;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom error page that should display for HTTP 404 errors. It
I have a php web page that now uses custom error pages when a
I am trying to create a custom error page for 404 errors. I have
I have a website which uses the custom 404 error handling in PHP/Apache to
I'm trying to return a custom 404 page using IIS6. (I have a site
I have a call to a 404 page in a controller: $this->set('title','Page Not Found');
I have custom error pages setup using <customErrors mode=On defaultRedirect=~/Home/Error> <error statusCode=404 redirect=~/Home/PageNotFound />
I have a Web Application which has Global_Asax and a Custom Error Page. When
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a few models that need to have custom find conditions placed on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.