I have a website where I use this .htaccess to remove the .php file extension from my links.
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://%{HTTP_HOST}/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
Now this works fine, but all the php that is inside the pages stops working. What could be causing this? And how can I fix it?
For example, I have a contact form on the website which display's fine. But does not work with the extension removed, as the PHP of the contact form is in the same file as the html markup. Now when I try to send a message with the extension removed, the message doesn't send and I don't get any notifications whether the message was sent or not. But everything works perfectly when the extension is there.
Also, the weird thing is. It still includes things like the header and footer, which I called through PHP.