I am using this snippet for enabling clean URLs, effectively removing the PHP extension.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
This works pretty well, but the problem is that I have some directories that share the same name as some of the PHP files.
So instead of the desired page, I get the directory structure.
I tried adding DirectorySlash Off
before all of the rewrite rules, but no luck with that.
I've read that I must remove the RewriteCond %{REQUEST_FILENAME} !-d
if I am using DirectorySlash Off
, that didn't work also.
Not to mention I tried around dozen various snippets when looking for a solution.
What is the proper way to handle my scenario?