how to remove php extention from url through htaccess

Discussion in 'PHP' started by dineshsingh1984, Jan 29, 2011.

  1. #1
    how to remove php extention from url through htaccess

    for example my url is "example.com/about.php" and i want display url this type : "example.com/about" with the help of htaccess file

    plz help me..............
     
    dineshsingh1984, Jan 29, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    RewriteEngine on
    RewriteRule (.*) $1.php
     
    G3n3s!s, Jan 29, 2011 IP
  3. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, you actually helped me :)
     
    CPAPubMichael, Jan 29, 2011 IP
  4. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #4
    No problem. But be aware! This would change all images, css & js !
    to prevent, replcae that with


    RewriteEngine on
    RewriteRule images\/(.*) images/$1 [L]
    RewriteRule css\/(.*) css/$1 [L]
    RewriteRules js\/(.*) js/$1 [L]
    RewriteRule (.*) $1.php [L]

    I hope you know you have to place css to folder /css, js to folder /js and so on ;)
     
    G3n3s!s, Jan 29, 2011 IP
  5. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So i would just need to put the code below to change the PHP pages only:

    
    
    RewriteEngine on
    RewriteRule (.*) $1.php
    
    
    HTML:
    Thanks,

    Michael
     
    CPAPubMichael, Jan 29, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    yep, that's true. If you have ONLY php files in that dir, or child dir, you can use these 2 lines :)
     
    G3n3s!s, Jan 29, 2011 IP
  7. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ahhh ok.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 29, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #8
    dineshsingh1984 if you have questions/problems, do not hesitate to PM/reply here
     
    G3n3s!s, Jan 29, 2011 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Would'nt something like this work better?

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.+?)$ $1.php
    Code (markup):
     
    danx10, Feb 1, 2011 IP
  10. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    I don't mind if it works for client(s) :)
     
    G3n3s!s, Feb 1, 2011 IP
  11. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    does this interfer with the get variables at all after the .php extension?
     
    srisen2, Feb 1, 2011 IP