I use PHP. I like to hide that I do. I used to have all of my PHP inside .html
files, but frankly it's annoying having to reconfigure every editor/tool I use that .html
actually means a PHP file.
So I've moved them all to .php, like a grown-up.
The extensions are hidden via try_files
anyway - I didn't know about that when I was first setting out.
But a user can guess www.domain.com/index.php
, and given that it loads fine, they'll know the site is built using PHP.
A minor issue, but one I'd like to quash. But how?
I naively tried this, near the top of my server
block:
location ~ (\.php$) {
return 404;
}
But that 404'd everything on the site. I guess because the location matches on the actual script that gets run, as opposed to what's in the user's address bar?
I then commented out the 404 line which had the LOVELY (/s) effect of sending my backend code to visitors as a download, along with their 404 page. I think because you can only match one location block, so it was matching, but then doing nothing with it, and just serving the code up?
Eurgh.
Before that I had tried
if( $request_uri ~ '\.php$' ) { return 404 ; }
In my server
block. But that didn't seem to have any effect.
Given the disaster I created, I've decided to ask the experts...
Thank you!