I want to run my PHP web pages on an apache web server without the .php extension. So I added the following code:
RewriteEngine on
RewriteBase /
Rewritecond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteRule (.*)$ $1.php [NC]
in the .htaccess file. This solves my problem but another problem arises. I cannot view the content of any directory (i.e. the file contained in the directory). Please provide me an alternate RewriteRule without this problem.
You need to make sure that the request URI points to an existing resource if you append the.php to the end of it:
the line
RewriteCond %{REQUEST_FILENAME}.php -fchecks if a “.php” is appended to the requested URI, it mapes to an existing file (-f).