1

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.

Tom
  • 11
  • 3
  • Define 'stops working'? – Daryl Gill Sep 05 '16 at 11:17
  • 1
    Possible duplicate of [Remove .php extension with .htaccess](http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – rahul Sep 05 '16 at 11:20
  • 1
    You might need to tell apache to parse extensionless files as php using DefaultType application/x-httpd-php. See this answer from the link @rahul posted: http://stackoverflow.com/a/4027458/532603 – Michael Sep 05 '16 at 11:27
  • Calling 'DefaultType application/x-httpd-php' did not work. Also, by stops working I mean that there is a contact form on one of my pages. But when it's used it doesn't send an email, and doesn't give a notification about whether the message was sent or not. – Tom Sep 05 '16 at 11:43
  • Are you facing this problem only on contact fourm? What is the destination url of your fourm? – Amit Verma Sep 05 '16 at 13:30
  • This ????? http://stackoverflow.com/questions/34080318/form-with-post-method-stops-working-when-php-extension-is-off – Amit Verma Sep 05 '16 at 13:35

0 Answers0