0

How can I remove .php extension from php files

htacess file

RewriteEngine On
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

any help is much appriciated, Thanks

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Have you looked at these questions: [My htacess doesn’t remove extension .php](https://stackoverflow.com/questions/25078376/my-htacess-doesn-t-remove-extension-php) [.htaccess removing of extensions](http://stackoverflow.com/a/23723477/2545927) – kkuilla Jan 20 '15 at 13:07
  • 1
    possible duplicate of [Remove .php extension with .htaccess](http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – philant Jan 20 '15 at 13:09

2 Answers2

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

If you go to example.com/test/ it will load example.com/test.php

rwacarter
  • 1,915
  • 1
  • 14
  • 25
0

For hat you should define an entry point.

Then you can rewrite your URLs to a parameter of a specified file in that case the index.php.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ index.php?url=$1 [NC,L]

Then you can filter that parameter in your script and show the correct content.

You have an URL something like:

www.example.de/test-test

Then everything is rewritten to your index.php. Other possibility if you rewrite to an existing file. You can do something like this:

RewriteRule ^(.*)/?$ $1.php [NC,L]

Then you fetch everything behind the slash and call an existing PHP file.

Remove .php extension with .htaccess

Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82