0

After some googling, I was able to allow my php website load without having to put the ".php", but I want to return an object not found error if it finds the ".php", hence making it a requirement to remove the ".php" extension.

Daniel Don
  • 232
  • 3
  • 9
  • Does this answer your question? [How can I create an error 404 in PHP?](https://stackoverflow.com/questions/1381123/how-can-i-create-an-error-404-in-php) – David Jones Aug 29 '21 at 10:30

1 Answers1

1

You could try something like this:

// PHP 8
if(str_contains($_SERVER["REQUEST_URI"], ".php")) {
    http_response_code(404);
    echo "404 - page not found";
}

// PHP < 8
if(strpos($_SERVER["REQUEST_URI"], ".php") !== false) {
    http_response_code(404);
    echo "404 - page not found";
}
Juri Salminen
  • 131
  • 1
  • 5