I've been searching all day for a solution to replace .php in the URL with a / using .htaccess. Most of the solutions didn't work for me at all (didn't rewrite the URL, even just to remove .php) until I found this beautiful solution on SO.
https://stackoverflow.com/a/11084526/1724376
Now my issue is that it only removes the .php but does not replace it with a "/". I've tried many things with no luck but I don't know much about htaccess and rewrite conditions, etc. I'm really hoping someone here can help me.
Just so I don't get down-voted for not having tried anything, here's one that I tried but it didn't rewrite the URL at all.
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
Help will be truly appreciated.
EDIT: To clarify, I want www.mysite.com/contact.php to show up as www.mysite.com/contact/
/it will try to serve a PHP file, but it will not redirect the browser in any way.[R=301]means a 301 HTTP redirect; without an[R]flag the rewrite is internal, and you'll often see[L], meaning "last", to stop both rules firing at once (they're processed in order, so the other option is to be careful how you list them). You say "of course ... example.com/test/ doesn't exist" - that's the point of the rule you've pasted here, to make that URL exist. My advice: get the "pretty" URLs working if you link to them directly first, then worry about redirecting people's browsers if they access the "legacy"/"ugly" URLs instead.example.com/test/, it exists (as far as the browser is concerned). Then you can do whatever you like to tell the browser to load that page (e.g. put in place 301 redirects from "old" URLs).