Daniel Don
Daniel Don

Reputation: 379

How do I make urls with ".php" return an "Object not found" Error?

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.

Upvotes: 0

Views: 47

Answers (1)

Juri Salminen
Juri Salminen

Reputation: 151

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";
}

Upvotes: 1

Related Questions