How to remove php extension form url with .htaccess?

by raphael_tillman , in category: Third Party Scripts , 3 months ago

How to remove php extension form url with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by addison , 3 months ago

@raphael_tillman 

To remove the .php extension from URLs using .htaccess, you can use the following code in your .htaccess file:

1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]


This code will remove the .php extension from URLs for files that exist on the server. For example, if you have a file named "example.php" and you want to access it without the extension, you can simply type "example" in the URL.


Please note that you need to have mod_rewrite enabled on your server in order for this code to work.