Friday, June 8, 2012

.htaccess to remove .PHP extension (Godaddy)

I have tried to remove the .php extension and nothing seems to work.

First, here is what I am trying to accomplish:

Current URL:
Desired URL:

Second, here is what I have in my .htaccess file:

Options -MultiViews

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteRule (.*)/$ $1.php [L]

Lastly, here is the issue:

Instead of getting I get and my pages can no longer find their css, js or image files. Also when I click an internal link it changes my url to and it will keep adding to the url as I click through the page until I get something like this:

The goal here is to just remove the .php file extension to the public as mentioned above.

Thanks, Ben

Source: Tips4all


  1. Use the following instead:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    The line with !-d checks that it's not a directory, the line with -f checks that the requested file is a .php file.

  2. I know this is an old post but hopefully this will help someone else.
    Below is what I have that works on Godaddy.

    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ $1.php [L]

    The only thing different is that I added the RewriteBase /