I've set up a .htaccess file to rewrite the url example.com/foo too example.com/foo.php I can separately get the URL to redirect to error.php if it ends in .php, but I can't seem to do both together.
I've seen other sites hide .php and I want to understand how to do that.
Here's what I've tried:
//.htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9-_]+)/?$ $1.php [NC,L]
RewriteRule ^([A-Za-z0-9-_]+).php?$ error.php [NC,L]
NOTES
Here is what worked for me. I'm going to leave it hear for reference as I'm not sure it all necessarily is necessary.
RewriteEngine On
RewriteRule (.*)index$ http://%{HTTP_HOST}/error [R=404]
RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php(\?.*)?\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/error [R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php
ErrorDocument 404 /error.php
ErrorDocument 301 /error.php
error.phpscript internally?.phpbut do exist, likeexample.com/foo