1

This isn't my exact PHP as it's rather complicated, but it's the same general idea.

if($_GET['page'] == ".htaccess"){
    header("HTTP/1.0 404 Not Found");
}

When this happens, Apache doesn't load the 404 page set in the .htaccess file. I know the 404 works because when I go to a non-existent page, I get the specified 404 page.

Is there any way I can get the specified 404 page to load without manually dumping the contents of the 404 page file?

  • Related question: http://stackoverflow.com/questions/5534268/headerhttp-1-0-404-not-found-not-doing-anything – User Aug 16 '14 at 02:29

2 Answers2

2

Since Apache already determined that the file actually exists, it wont look for 404 again.

One workaround could be actually sending a Location-header to a actual non-existant page and let Apache handle it. Another could be fetching the 404 page contents through PHP and outputting it together with a Status: 404-header

hank
  • 3,748
  • 1
  • 24
  • 37
  • I was afraid of that. I'll let this question sit for a day or two and see if any magical hacks have been found, but if not I'll accept this. –  Feb 25 '13 at 07:33
0

This may Work

if (strstr($_SERVER['REQUEST_URI'],'.htaccess')){
    header('HTTP/1.0 404 Not Found');   
    exit();
}
tony
  • 139
  • 1
  • 3