Remove .php suffix from URL's with .htaccess

When an URL with .php suffix is called on site, the suffix should be removed. An example URL would be

domain.com/something/page.php

and if this URL is visited, the browser should be redirected to

domain.com/something/page

What rule in .htaccess would do it? It's a sub-site of a Multisite.

  • mirecart
    • Design Lord, Child of Thor

    Hi Predrag,

    I've entered into .htaccess and it now looks like this, the same error still comes up.

    Please advise,

    Regards,

    Mick

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]

  • mirecart
    • Design Lord, Child of Thor

    Given this was an old domain ext of .uk and the new website is .co.uk i have created a folder on my server and place an index page, along with .htaccess with the following code which is working fine.

    Not the best results, but my client is happy his site links don't get error codes.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ / [L,QSA]
    </IfModule>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.