using htaccess to remove .php file extensions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

using htaccess to remove .php file extensions

Post by cjkeane »

Hi everyone.

I'm trying to remove .php extensions from all my .php files using .htaccess. It is partially working.

what i am using is:

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

What I need it to do is remove the .php extension when the page is visited, like so:
http://mysite.com/about.php
http://mysite.com/about

*mysite.com is a domain name just used as an example

I can go directly to http://mysite.com/about and the page loads, properly, but if i navigate from within the site to the about page, the url returns to http://mysite.com/about.php.

I've tried many different ways to write the rewrite statement, but it doesn't remove the .php extension when navigating to that menu from within the site.
Any ideas why this might be happening?

*since posting, I resolved my issues

Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: using htaccess to remove .php file extensions

Post by requinix »

You need to fix your links so they all say /about and not /about.php.
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: using htaccess to remove .php file extensions

Post by cjkeane »

yes I realized that about a half hour before you replied! thanks!
Everything works great now!
Post Reply