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
Victor Levytskiy
7,608 PointsHide .html extension from a page address
How I can hide page extension .html from a web page address.
Example:
before example.com/contact.html
after example.com/contact/
Thanks :]
2 Answers
Samuel Webb
25,370 PointsCheck out THIS WEBSITE which discusses the use of .htaccess files and how to use them to remove .php, .html and .htm file extensions from your URL.
edwardsnowden
4,813 Pointsto answer you properly, .html hasn't been removed in your "after" example.
/contact/ = /contact/index.html
but you don't see index.html displayed because it is the default file.
Samuel Webb
25,370 PointsThe problem with this approach is that if someone actually goes to the URL bar themselves and types in example.com/contact/index.html (or if someone has that link bookmarked) it will still show up in their browser as example.com/contact/index.html. For example, if you go to my website by typing codingtestsite.com, it won't show the index.php file. But if you type in codingtestsite.com/index.php, it will now show in the URL bar. By using a .htaccess file, I'd be able to redirect them so they could type it in either way and it would still always show codingtestsite.com in the URL bar.
Samuel Webb
25,370 PointsAlso, by using .htaccess files, it prevents you from having to name all your different pages index.html. You could have example.com/contact/contact.html and you could set up a rule that looks for contact.html to be the primary file to open inside of the contact/ directory.