Page 1 of 1
Removing .php extension
Posted: Wed May 18, 2011 7:20 am
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?
Re: Removing .php extension
Posted: Wed May 18, 2011 11:08 am
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
Re: Removing .php extension
Posted: Wed May 18, 2011 11:22 am
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.
Re: Removing .php extension
Posted: Wed May 18, 2011 12:27 pm
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
Re: Removing .php extension
Posted: Wed May 18, 2011 1:08 pm
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.
Re: Removing .php extension
Posted: Wed May 18, 2011 1:45 pm
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 !
Re: Removing .php extension
Posted: Wed May 18, 2011 3:00 pm
by nyo
jacek wrote:you cant load modules in .htaccess file
Nice to learn that.
nailyener wrote:I recommend getting a less stupid host !
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
I use Hostgator.