Removing .html from url of a html website

Discussion in 'HTML & Website Design' started by sourabhkejriwal, Feb 26, 2014.

  1. #1
    Hi all,
    I have made a website in html of which I would like to change URL.
    I want to make : mywebsite.com/index.html to mywebsite.com

    and remove .html from all other pages like:
    mywebsite.com/contact.html to mywebsite.com/contact

    Please help
     
    sourabhkejriwal, Feb 26, 2014 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    To do that, place each file in its own appropriately named directory. Rename the file index.html. Thus:
    example.com/ delivers the home page
    example.com/aboutus/ delivers the index.html page in that directory as the aboutus page.

    Don't forget the trailing virgule.

    cheers,

    gary
     
    kk5st, Feb 26, 2014 IP
  3. oneilonline

    oneilonline Greenhorn

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #3
    Why would someone want the .html dropped...???
     
    oneilonline, Feb 26, 2014 IP
  4. sourabhkejriwal

    sourabhkejriwal Member

    Messages:
    85
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Because I think this looks good.
    eg: 'Google.com/index.html' doesn't looks good as Google.com
     
    sourabhkejriwal, Feb 27, 2014 IP
  5. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    406
    Best Answers:
    21
    Trophy Points:
    295
    #5
    RewriteEngineOn
    RewriteCond%{REQUEST_FILENAME}!-f
    RewriteCond%{REQUEST_FILENAME}!-d
    RewriteRule^(.*)\.html$ /$1 [L,R=301]

    try that in .htaccess
    Nigel
     
    Nigel Lew, Feb 27, 2014 IP
  6. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #6
    He is obviously new. Let me break this down for you.

    htaccess is a file you create in your main directory. It lets you drop file names and manipulate URLs for purposes such as SEO. To begin create a file called .htaccess. This means put nothing ahead of the dot, I'm not talking about something like .htaccess.txt. The file literally has no name.

    After you create your file open it in your favorite text editor and place Nigel's code in. Now you URLs will look like this if all files are in the same directory:

    Index: domain/
    Random page: domain/random-page/
    Profit???: domain/profit/

    :D Enjoy!
     
    Grimmfang, Feb 28, 2014 IP
    Nigel Lew likes this.
  7. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    406
    Best Answers:
    21
    Trophy Points:
    295
    #7
    Good point. For some reason, I was thinking I was in the Wordpress board.

    Nigel
     
    Nigel Lew, Feb 28, 2014 IP