How to remove .html ending from the page links

Discussion in 'HTML & Website Design' started by ademmeda, Apr 11, 2011.

  1. #1
    ademmeda, Apr 11, 2011 IP
  2. shrkscn

    shrkscn Peon

    Messages:
    1,157
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Read this...

    
    http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
    
    Code (markup):
    its about removing file extensions via .htaccess
     
    shrkscn, Apr 11, 2011 IP
  3. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #3
    Thank you very much, I will check it now.
     
    ademmeda, Apr 11, 2011 IP
  4. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #4
    UPDATE: I tried the code and it worked. I will post the code here as well, since that blog post might be removed in the future.

    This will remove file extensions like .html, .php, .asp and so on.
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html
    # Replace html with your file extension, eg: php, htm, asp
    Code (markup):
    This one will add a trailing slash to the end, like website.com/home/

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^([^/]+)/$ $1.html 
    
    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    Code (markup):
     
    ademmeda, Apr 12, 2011 IP
  5. brit.anica

    brit.anica Well-Known Member

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    wow, I didn't knew like this existed! i thought that ( site.com/page/ ) can only be done in php/asp

    I will check this on my site too!!

    ++Rep
     
    brit.anica, Apr 12, 2011 IP