How to hide .php extension

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
jerrellbryant
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 8:30 pm

How to hide .php extension

Post by jerrellbryant »

Hello Everyone,

I am attempting to hide the .php extension on my website so that link to my pages will not look like this ( .../pages/test.php) but rather look like this ( .../pages/test/ ) .

I have been google searching for answers and received a bunch of articles but none of the methods discussed seem to work for me... I contacted my host provider which happens to be 1and1.com and was informed the server is running Apache, so I have attempted to use .htaccess file with the following code :

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
ServerSignature Off

but it is not working properly.. can someone point me in the right direction... maybe I need additional files to make above work? Please help

Thank You
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to hide .php extension

Post by Benjamin »

:arrow: Moved to Installation and Configuration
jerrellbryant
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 8:30 pm

Re: How to hide .php extension

Post by jerrellbryant »

Can anyone help me with this issue? I have still not resolved. Thanks In Advance.
dev008
Forum Newbie
Posts: 10
Joined: Wed May 12, 2010 3:34 am

Re: How to hide .php extension

Post by dev008 »

Hello,

please use the givne below code it will solve you problem... :drunk:


Options +FollowSymLinks -MultiViews -Indexes

RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} !^401$
RewriteCond %{REQUEST_URI} !^/(payment|admin|provider|partner)/
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ dispatcher.php [L]


thanks!
thephpexpert
jerrellbryant
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 8:30 pm

Re: How to hide .php extension

Post by jerrellbryant »

Dev008 thank you for your help. So I would take the script you have provided and place it in my .htaccess file and place it on the root correct?
Post Reply