Friday, December 14, 2012

Hiding file extension in web browser via .htaccess

I want to hide (remove) the file extension  (shtml) in my web page. The website is hosted in an apache server running a linux operating system.

I have tried various codes (found in google search: removing file extension) written in .htaccess files, but give me no luck. 

After keep on trying and modifying codes from several sources, finally I can get what I want:
domain/foo.shtml will be appeared as domain/foo
and if I type
domain/foo it opens the shtml page correctly and appeared as domain/foo
Basically the *.shtml will never appeared in the web browser address bar.

The codes written in .htaccess are the following:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.shtml -f
RewriteRule ^(.*)$ $1.shtml
RewriteCond %{THE_REQUEST} ^GET\s.+\.shtml
RewriteRule ^(.+)\.shtml$ /$1 [R=301,L]

The codes are implemented in the new Impact website. Note in IE9, some pages are greyed-out because lightbox.js does not work correctly.

12 comments:

  1. The codes also work for other extensions.

    ReplyDelete
  2. This is a very nice article on htaccess i like your article.

    ReplyDelete
  3. Thank you. The link about htaccess http://www.htaccessredirect301.com/
    is very useful.

    ReplyDelete
  4. I really like your blog,this blog is very useful for me in my future.Thanks to you keep it up.Here is a browser extensions you can use this your motive:- https://chrome.google.com/webstore/detail/yourls/cfmnkhhioonhiehehedmnjibmampjiab

    ReplyDelete
  5. really nice article i like your post

    ReplyDelete
  6. that was really helpful.I must say you are great.





    top outsourcing companies

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete