How to add ".php" extension using ".htaccess" file?

by darrion.kuhn , in category: Third Party Scripts , 3 months ago

How to add ".php" extension using ".htaccess" file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 2 months ago

@darrion.kuhn 

To add the ".php" extension to files using the ".htaccess" file, you can use the following code in your ".htaccess" file:

1
2
3
4
5
6
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([^.]+)$ $1.php [NC,L]
</IfModule>


This code will add the ".php" extension to any file requested that does not already have an extension. For example, if you request "example" the server will serve "example.php" if it exists.