Removing .php extension

Ask about a PHP problem here.
Post Reply
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Removing .php extension

Post by nyo »

Hi,

I am trying to remove .php extension from the URLs on my site. The .htaccess file I am using works on localhost, but when I upload it to server, it doesn't work.

Server has PHP4 and PHP5 but the default is PHP4, therefore I am using an extra piece of code to make PHP5 the default handler. Here is the .htaccess file:
AddHandler x-httpd-php5 .php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Am I doing something wrong?
User avatar
element
Posts: 8
Joined: Mon May 16, 2011 7:20 pm
Location: Germany

Re: Removing .php extension

Post by element »

I dont know alot about these htaccess stuff but this following code works fine for me....
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: Removing .php extension

Post by nyo »

element wrote:I dont know alot about these htaccess stuff but this following code works fine for me....
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Didn't work for me, it gives a 404 error just like the code I am using. As I said, it works on localhost but not on the server, it's strange.
User avatar
element
Posts: 8
Joined: Mon May 16, 2011 7:20 pm
Location: Germany

Re: Removing .php extension

Post by element »

ok try to ckeck if the module is loadet...
use the phpinfo() funktion and than

under Apache->Loaded Modules... there must be a entry "mod_rewrite".
When it´s not loadet try to load it with "LoadModule rewrite_module modules/mod_rewrite.so" in youre htaccess file
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: Removing .php extension

Post by nyo »

element wrote:ok try to ckeck if the module is loadet...
use the phpinfo() funktion and than

under Apache->Loaded Modules... there must be a entry "mod_rewrite".
When it´s not loadet try to load it with "LoadModule rewrite_module modules/mod_rewrite.so" in youre htaccess file
You are right, mod_rewrite is not loaded on the server. I added the following line to my .htaccess but it gave an error 500.

LoadModule rewrite_module modules/mod_rewrite.so

I guess I will have to contact the server provider.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Removing .php extension

Post by jacek »

nailyener wrote:You are right, mod_rewrite is not loaded on the server. I added the following line to my .htaccess but it gave an error 500.

LoadModule rewrite_module modules/mod_rewrite.so
you cant load modules in .htaccess file ;)
nailyener wrote:Server has PHP4 and PHP5 but the default is PHP4,
I recommend getting a less stupid host ! :lol:
Image
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Re: Removing .php extension

Post by nyo »

jacek wrote:you cant load modules in .htaccess file ;)
Nice to learn that.
nailyener wrote:I recommend getting a less stupid host ! :lol:
This is not my website I am working on, it is my friend's. I wouldn't come closer than a hundred miles to such a host :x I use Hostgator.
Post Reply