Pergunta

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?

Foi útil?

Solução

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

Outras dicas

This may Work

if (strstr($_SERVER['REQUEST_URI'],'.htaccess')){
    header('HTTP/1.0 404 Not Found');   
    exit();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top