How to hide PHP file extension without using .htaccess

Although you specifically said no, using the .htaccess file would remove the .php extension from all PHP files in all subdirectories in a site. I think that is what you are going for.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^(.*)$ $1.php
</IfModule>

Putting that into the .htaccess file will remove all the .php file extensions. Or you could put it directly into the webserver’s configuration files.

Leave a Comment