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?

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

This may Work

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.