How to remove php extension form url with .htaccess?

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

How to remove php extension form url with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by addison , 8 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.

Related Threads:

How to remove the .php extension in .htaccess file?
How to remove url parameters in php using .htaccess?
How to add .php extension in htaccess in laravel?
How to add ".php" extension using ".htaccess" file?
How to remove .cgi from url with .htaccess?
How to remove get parameter from url with .htaccess?