Aaron Walker
Aaron Walker

Reputation: 185

How do I remove the '.php' extension from URLs?

This is where the PHP files are:

ts1.WEBSITENAMEHERE.biz/cp/

The .htaccess file is also in this folder. I want to remove the '.php' from 'FILENAME.PHP'.

This is my current '.htaccess' file:

Options +FollowSymlinks
RewriteEngine on 
RewriteBase /cp
RewriteRule ^(.*)/$ $1.php

But it is not working. Why is this?

Upvotes: 1

Views: 2511

Answers (3)

Cybercartel
Cybercartel

Reputation: 12592

    Options +FollowSymlinks
    RewriteEngine on 
    RewriteBase /cp
    RewriteRule ^(.*) $1.php

I use this checker: http://htaccess.madewithlove.be

Upvotes: -1

ppsreejith
ppsreejith

Reputation: 3458

Create a .htaccess file in the DocumentRoot dir. Add the following code in that file...

##############
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^(.*)$ %{REQUEST_URI}.php [R]
#############

mod_rewrite should be enabled for this to work.

Upvotes: 0

zerkms
zerkms

Reputation: 255005

RewriteEngine on
RewriteBase /cp/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]

Upvotes: 3

Related Questions