Removing .php extension from URLs

Discussion in 'PHP' started by ademmeda, May 18, 2011.

  1. #1
    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 line 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]
    
    Code (markup):
    Am I doing something wrong?
     
    ademmeda, May 18, 2011 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    ive tried your code to my localhost, hmm.. it doesnt work.. different behavior, it is downloading the script and opening to other format.


    heres the one i use..
     
    bartolay13, May 18, 2011 IP
  3. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #3
    This is the one I use on the server. I remove "AddHandler x-httpd-php5 .php" on localhost, because I already have PHP5 on localhost. I guess the one you are using changes one single page.
     
    ademmeda, May 18, 2011 IP
  4. quicklink

    quicklink Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You should use mod rewrite rules in your htaccess file that can be done by mod rewrite only
     
    quicklink, May 18, 2011 IP
  5. KastorPM

    KastorPM Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    RewriteCond %{REQUEST_URI} !index.php$
    RewriteRule ^[A-z0-9\-_\/]+\.php index.php
     
    KastorPM, May 18, 2011 IP
  6. zerokvl

    zerokvl Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php?page=$1&pag=$2 [QSA,NC,L]

    This is what i use in my htaccess, and the urls i made them with request_uri. It`s more easier, and you can control all your link extentions.
     
    zerokvl, May 18, 2011 IP