0

I'm trying to remove all .php extensions with the following...

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

However I have a directory - mysite.com/example/ which will no longer show the index.php file, instead, I have to visit mysite.com/example/index. I'm sure there must be a work-around for this? Thanks

EDIT: The aim is to be able to visit mysite.com/example/ and load the index page as normal. But for files such as mysite.com/example/test.php the .php extension will be removed and will load from the link mysite.com/example/test

inTheGrind
  • 35
  • 9
  • Looks like you are missing some htaccess rules/directives so check out this possible duplicate [put links without file extension (.php)](https://stackoverflow.com/questions/18018311/put-links-without-file-extension-php) – MonkeyZeus Aug 27 '18 at 13:13
  • 1
    I've just tested it and the second answer works: https://stackoverflow.com/a/18018569/2191572 – MonkeyZeus Aug 27 '18 at 13:19
  • Yes that worked, thank you! – inTheGrind Aug 28 '18 at 12:29
  • Nice, please go ahead and mark your question as a duplicate of the one I suggested. You should see a yellow banner above your question with instructions. – MonkeyZeus Aug 28 '18 at 15:29

1 Answers1

0

Please add this code in .htaccess file

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

Options -Indexes
DirectoryIndex index.php index.html

Note : above options and directory index lines allows a specific file to load just in case there is no default index file already set up

Sunny Kalariya
  • 336
  • 2
  • 9
  • I think the DirectoryIndex should include index as well so it becomes: `DirectoryIndex index.php index.html index` – Nadir Latif Aug 28 '18 at 03:21