Reputation: 15
I used this code to remove the .php file extension on my website
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
This worked to change my url from example.com/contact/contact.php to example.com/contact/contact but I would like the url to not have the file name after the folder that it is in. I would like it to look like example.com/contact/ Any thoughts?
Upvotes: 0
Views: 79
Reputation: 96
An easy way to do this is by naming the file index.php when navigating to the folder, the index.php file wil be served. So when navigating to /contact /contact/index.php will be displayed.
https://en.wikipedia.org/wiki/Webserver_directory_index
Upvotes: 1