Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove .php file extension

    Hello Everyone,

    I am trying to find a way to get clean url with .htaccess;

    For example I want http://mysite.com/something not http://mysite.com/something.php

    I have this code

    Code:
    Options +FollowSymLinks
    RewriteEngine On
     
    # Remove trailing slashes.
    # e.g. example.com/foo/ will redirect to example.com/foo
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]
     
    # Redirect to PHP if it exists.
    # e.g. example.com/foo will display the contents of example.com/foo.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+)$ $1.php [L,QSA]
    It works when I remove the .php myself but I want it to remove it automatically. Instead of me going to the navigation php include and removing the .php to the link. Is that possible?

    Thank you.

  • #2
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Try this
    Code:
    RewriteRule ^(.*)/$ /$1.php [L]
    you woud get http://mysite.com/something/ FROM http://mysite.com/something.php


    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •