Treehouse: Grow your CSS skills. Land your dream job.

How to set up site for links without “html” extension

  • # August 3, 2012 at 8:34 am

    This may be a silly question, or I feel at any rate that the answer should be more obvious, but I am wondering how to set up a site so that the links do not include the “.html” file extension. I.e.:

    and not:

    I’ve previously been developing within WordPress and so this happened automatically, but how does one do this for a stand alone site. Some methods that I’ve come across already are: setup a series of folders each with their own index.html files, or add the following lines to .htaccess:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.+).html$ $1 [L,NC,R=301]

    Do people here have a sense of what’s the best method?

    # August 3, 2012 at 1:36 pm

    It would be cleaner to just use HTACCESS.

    # August 3, 2012 at 3:55 pm

    You would do this in the htaccess file.

    RewriteEngine On

    # Redirect to HTML if it exists.
    # e.g. will display the contents of
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L,QSA]

    # August 3, 2012 at 5:50 pm

    @AlexHackney: Thanks! I will give this a try.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.