Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39192
    ethanmiller
    Participant

    Hi,
    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.:

    mysite.com/blog

    and not:


    mysite.com/blog.html

    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?

    #107272
    chrisburton
    Participant

    It would be cleaner to just use HTACCESS.

    #107277
    AlexHackney
    Participant

    You would do this in the htaccess file.

    RewriteEngine On

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

    #107281
    ethanmiller
    Participant

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Other’ is closed to new topics and replies.