Executing PHP without .php file extension

Hi guys,

first let me say I like caddy for its simple configuration and LE integration. Second, please help me set caddy to execute PHP-FPM for URLs without extension (.php), for example URL Custom Application Development Software for Business - Salesforce.com will execute www.site.com/phpinfo.php, but hide .php extension in the reply URL. For apache I have this .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Thank you in advance.

xP

Usual practice is to to have phpinfo/index.php instead there xP! :joy:

Another usual practise is to hide file extensions, so please lets solve the configuration, not practice. There are several .php files in the current directory and rename all files to index.php and move them to their own directories is not cool.

Have you tried the ext directive already?

2 Likes

This should be enough

ext .php

If you still want to use rewrite, the direct conversion of that rewrite rule will not server any file other than .php

rewrite {
    r    (.*)
    to   {path}/ {path}.php {1}.php
}

But this is better as it serves other files if they exist.

rewrite {
    to   {path}/ {path} {path}.php
}

To conclude, in this case I will rather follow Caddy’s philosophy and keep it simple by using ext .php.

2 Likes

ext .php

works for me as expected. Thank you guys.

xP

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.