-1

The last few days, I've really been messing with the .php extension. I used mod_rewrite (via .htaccess) to redirect from www.example.com/example.php to www.exmaple.com/example and it works fine. But I found out that I could still enter the url www.example.com/example.php to visit the page rather than show a not found page. How could I do that?

This is what I mean:
If you try to entered the first link before, it will work fine but the second link is the Forum page from phpacademy it will redirect to a error page. But my page will still work fine too. I want the effect like this.
Forum page without .php extension
Forum page with .php extension

Much appreciate any help

Till Helge
  • 9,253
  • 2
  • 40
  • 56
  • see also http://stackoverflow.com/questions/7823801/remove-php-extention-stop-access-of-url-with-php-extention-and-remove-trailing | http://stackoverflow.com/a/7823959/689579 – Sean Jul 26 '14 at 16:47

1 Answers1

1

You could have following as .htaccess:

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