Removing the .php extension?

Discussion in 'PHP' started by UCDaZ, May 4, 2009.

  1. #1
    I'm using this .htaccess code to remove my .php extension

    <code>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ $1.php [L,QSA]
    </code>

    Let's say I have a called FileCode.php.
    I can load that file with no problem in my browser as www.domain.com/FileCode

    However, when I try to retrieve a parameter like www.domain.com/FileCode/param1, my FileCode is not able to be run.
    It only works when I have www.domain.com/FileCode.php/param1


    What can I do to fix the .php extension problem?
     
    UCDaZ, May 4, 2009 IP
  2. seokingdom07

    seokingdom07 Banned

    Messages:
    132
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is there any other way do the same?
     
    seokingdom07, May 5, 2009 IP
  3. GreenWithEnvy

    GreenWithEnvy Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([.\/]*)$ $1.php [L,QSA]

    Try this. Let me know if it works.

    Matthew
     
    GreenWithEnvy, May 5, 2009 IP
  4. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JDevereux, May 5, 2009 IP
  5. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    but what if I want to have more than one parameter?
    For example,
    domain.com/param1/param2/...paramN
     
    UCDaZ, May 5, 2009 IP
  6. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think you will need a specific rewrite rule for all your pages that take paramaters:

    RewriteRule Filecode\/(.*)$ Filecode.php/$1 [L,QSA]
     
    JDevereux, May 6, 2009 IP