How to not need to type .html

Discussion in 'Web Design and Development' started by mackncheese, Nov 10, 2009.

  1. mackncheese macrumors member

    Aug 20, 2009
  2. angelwatt Moderator emeritus


    Aug 16, 2005
    You misspelled your link.

    If you're on an Apache web server and all of your files end in .html then you can use a rewrite rule to redirect to the URL with a .html ending.

    RewriteEngine On
    # If request does not end in .html or /
    RewriteCond %{REQUEST_FILENAME} !^(.*)(\.html|\/)$
    # Add .html to the end of the request
    RewriteRule ^(.*)$ $1.html
    I wasn't able to test this, but the idea is sound.
  3. jc1350 macrumors 6502a

    Feb 4, 2008
    You may be confusing a directory with a file. web servers are nothing but glorified file servers, and as such, you have to in some way specify a file.

    A URL that doesn't specify the file is typically a directory that has an index file (a file with a particular name such as index.html, homepage.html, etc) or it is a file system link (ex: symbolic link in the world of UNIX/Linux) that points to a file. The actual name of the index file can be anything imaginable as long as it's specified as such in the web server configuration and there can be more than one index file name defined) or it's the target of a symlink.

    Exampe: let's say a site uses "index.html" for index files.

    When you go to _http://www.mysite.tld/, the server automatically looks for the index file "index.html" since no file name was included in the URL and that is the file served. If no file has an index name (index.html in this example), then the url _http://www.mystie.tld/ will either produce a directory listing or a "directory browsing not allowed" error, depending on the server/site config.
  4. design-is macrumors 65816


    Oct 17, 2007
    London / U.K.
    I don't know if this works as I've not tried it yet, but I read this advice in another forum a while back:

    Let us know if you try and it and if it works ;)

  5. Les Kern macrumors 68040

    Les Kern

    Apr 26, 2002
    What he said.
    Either change lounge.html to index.html, or add lounge.html to the suffix list.
  6. mackncheese thread starter macrumors member

    Aug 20, 2009

Share This Page