Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Mark Lawson
Mark Lawson
6,148 Points

Removing .html from url

When we save html docs they have a .html at the end. When I upload my site and then go to each page the url shows the page with the .html showing. I want to remove the .html.

Example: Your site shows- https://teamtreehouse.com/community

If this was my site it would show- https://teamtreehouse.com/community.html

How do I remove the html?

Thanks

Mark

6 Answers

You need to create a file called '.htaccess' in the root directory of your site containing the following code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

And then make sure all the links on your site don't contain '.html' at the end, e.g.:

<a href="/about.html">

should be replaced with:

<a href="/about">

Hope this helps! If you need more help with the .htaccess file, google has a ton of results on it

Mark Lawson
Mark Lawson
6,148 Points

Thank you, where do I place the ht access file? How do I make an ht access file.

Regards

Mark

You just need to create a new file using your text editor the same way you would any other html or css file, but save it as simply '.htaccess'

And save it into the root directory, so the same folder that you have your index.html file.

Mark Lawson
Mark Lawson
6,148 Points

Thanks, I will give it a go.

Mark Lawson
Mark Lawson
6,148 Points

OK, I have copied and pasted your code into a code editor and saved it as htaccess.txt; not sure if this is right; however, it has not worked. I am hoping at this point you can tell me where I have gone wrong.

Thanks

Mark

Oh all you need to do is change the name of the file.

Instead of 'htaccess.txt' it should be '.htaccess'

So .htaccess is the file extension but it has no name

I hope that makes sense

Mark Lawson
Mark Lawson
6,148 Points

You are a star!! The only, and best answer by far.

Haha no problem I'm glad I could help!

Mark Lawson
Mark Lawson
6,148 Points

I have voted you best answer. Thank you