Get a free trial // Grow your CSS skills // Land your dream job

hide .html with .htaccess not working – Please Help

  • # November 4, 2012 at 11:49 am

    the file name is simply **.htaccess** nothing before the period

    I wanted to remove the extension to clean my urls. I was working with static html files.

    Prior to removing the extension, the url would read ****.

    With the extension removed, it would look like ****. Hope that was clear.

    # November 4, 2012 at 11:54 am

    Basically it makes them look “pretty”.

    # November 4, 2012 at 12:35 pm


    You’re thinking about this a little backwards. You should be using .htaccess to transparently redirect the user to the real file when the file extension is left off:

    `/file` => `/file.html`

    This keeps the URLs “pretty” (the user never sees the `.html`) while keeping everything working.

    In order to “remove” the file extensions from the URL, you should simply *remove* them: *don’t type* `/file.html`, just type `/file`.

    From some of your earlier comments, I thought you’d figured that out:

    > I was able to solve the problem by changing the structure of the page links in html.

    but maybe there’s still some confusion?

    If the user types in whatever`.html`, there’s no real point in removing it for them via .htaccess – if it works anyway, why “fix” it?

    — If the user wrote it, it’s obviously not “unfriendly” to them.

    — Search engines see what’s written in hyperlinks, not what users type in their address bar. As long as your hyperlinks are “pretty,” everything is fine.

    At best, you’re just adding two or three unneeded HTTP requests per page view.

    # November 4, 2012 at 12:58 pm


    Thanks for the response. I resolved the issue quite some time ago — just wanted to respond to a few users with questions regarding similar issues.

    # November 4, 2012 at 2:09 pm

    okay, no problem. I wasn’t sure.

    # February 4, 2013 at 8:05 pm

    Hi Rugg, I follow your code below

    RewriteCond %{THE_REQUEST} /(.+/)?index(.html)?(?.*)? [NC]
    RewriteRule ^(.+/)?index(.html)?$ /%1 [R=301,L]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^(.+).html$ /$1 [R=301,L]

    RewriteCond %{SCRIPT_FILENAME}.html -f
    RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]

    and it works fine.
    However, because I use 2 files for contact page which is contact.html and contact.php
    When I type /contact the html page cannot load.

    Do you know why does it happen and how to fix it?
    Thanks a lot.

    # May 20, 2013 at 6:21 am

    **I there I Am new with httacces **

    Extension .html but i can hide using this rule .. help

    # August 9, 2013 at 10:28 pm

    Hi All,

    I can’t get this to work at all :-/

    The pages load fine, I get no errors, but the .html extensions are still visible in the browser, any ideas?


    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteBase /
    RewriteEngine on
    RewriteCond %{REQUEST_fileNAME} !-d
    RewriteCond %{REQUEST_fileNAME} !-f
    RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [L]

    # August 10, 2013 at 8:53 pm

    Extension .html but i can hide using this rule .. help


    the .html extensions are still visible in the browser, any ideas?

    please read earlier posts.

    mod_rewrite does not change your hyperlinks.

    You change your hyperlinks. If you want the address in the browser’s address bar to be


    instead of


    then open up your text editor and change the hyperlink. mod_rewrite will put the .html back on the URL so it still works.

    . . . . . . . . . . . . . . . . . . . . . . . . .

    Please don’t take offense; and I apologize if I sound frustrated. This question has been coming up a lot lately.

    . . . . . . . . . . . . . . . . . . . . . . . . .

    p.s. your rewrite rule could probably be simplified to

    RewriteRule ^(.*)$ $1.html

    …unless you were trying to accomplish something specific by writing it the other way.

Viewing 9 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed