Deny php extension, but convert HTML extension to PHP

1. The problem I’m having:

I have a page called index.php. I want the user can call it by HTML extension. I already done it with the line:
uri replace .html .php
But I want the user can’t call PHP extension directly. Resuming, if the user call directly index.php, the request would be denied (404 error). But if the user call index.html, the request redirect to real index.php. I tried:

@php path *.php
respond @php 404 
uri replace .html .php 

But this way, all requests are denied.

2. Error messages and/or full log output:

No error message. Only… all the requests are denied

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

a. System environment:

Debian Linux 11.0
Caddy binary file

b. Command:

caddy run --config Caddyfile

d. My complete Caddy config:

:9191 {
	root * /home/paulo/projeto_php
	encode gzip
	file_server {
		hide .git
    @php path *.php
    respond @php 404   

    uri replace .html .php

	try_files {path} index.html


This implies that you’re setting your webroot to the root of your git repo. That’s not the right way to do it.

Modern security best-practice is to have a public directory which contains your index.php, and you set your server’s webroot to that public/ directory. This makes sure users can’t browse through the rest of your source code, and you can control what’s accessible by putting assets in public/.

I’m confused about what you’re trying to do. It doesn’t really make sense.

The modern way to write PHP apps is to have all requests go through index.php (which is the default behaviour of php_fastcgi) and your index.php routes the request based on REQUEST_URI to run whatever code is necessary. PHP frameworks make this easy.

I would like to hide the tecnology that my sites uses. So I’d like my pages don’t answer if called directly with the php extension. I’d like it answer only calling html extension.
(I don’t write in english very well. Please forgive some mistake…)

That doesn’t gain you anything. Something like 70% of websites use PHP anyway. Trying to hide that does nothing.