I have two pieces of code that removes the .php extension.
Solution 1:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Solution 2:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
directory is a directory
page is a page
problem with solution 1:
if you go to domain.com/directory, it is supposed to show domain.com/directory/index.php but the index.php does not appear and it just shows a 404 error page.
problem with solution 2:
if you go to domain.com/directory/page/haha-lol-blah-blah, the page domain.com/directory/page shows up, no matter what is after the page.
is there a solution for both problems?
here is what i need:
domain.com/directory -> shows the page: domain.com/directory/index.php
domain.com/directory/page -> shows the page: domain.com/directory/page.php
domain.com/directory/page/haha-lol-blah-blah -> invalid page (404)
I believe this is working now with this code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Try it like this,
#incoming request neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ $1.php [L]