Page 1 of 1

using htaccess to remove .php file extensions

Posted: Fri Jan 22, 2016 8:35 pm
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.

Re: using htaccess to remove .php file extensions

Posted: Fri Jan 22, 2016 9:55 pm
by requinix
You need to fix your links so they all say /about and not /about.php.

Re: using htaccess to remove .php file extensions

Posted: Fri Jan 22, 2016 10:21 pm
by cjkeane
yes I realized that about a half hour before you replied! thanks!
Everything works great now!