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

remimatia
2,871 PointsBetter URL's for SEO
Hi
In some blogs I see: http://www.example.com/themes/how-to-do-better-seo
I was trying to do that renaming the page without the html extension, but I can't because I create a broken link
for example, I want to create: http://www.example.com/gallery
How can I achieve that without the .html extension?
so the code will be:
<a href="gallery">Click to see my photos</a>
but I need to put the html extension in order to make the link works:
<a href="gallery.html">Click to see my photos</a>
so the url will be:
http://www.example.com/gallery.html
but I dont want that
thanks!
12 Answers

remimatia
2,871 PointsI had to leave the links without the html extension, I found another option:
Options +MultiViews
you put there in your htaccess file. Also, It worked with links without the html extension
thanks!!

James Barnett
39,199 Points@Aldo -
You can always test your htaccess syntax using the htaccess tester

Suleiman Leadbitter
15,805 PointsEasiest way. You would need the gallery as an index.html in a gallery directory.
The other way is using the .htaccess to jiggery pokery with it. Do a search for 'Removing HTML file extension with htaccess' or if you are using a CMS such as WordPress there is probably an awesome extension.

Vaibhav Kanwal
1,199 PointsI find .htacess way a little difficult for my understanding. I use the permalink options in WordPress as its very easy to work with.
Set it and forget it
There's a great book on HTACCESS if you'd like to learn more on this
htaccess Book by Jeff Star

robbrazier
6,524 PointsHave a look here for removing the file extension: http://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/
Remember though, add RewriteEngine On
at the top of your htaccess file.

remimatia
2,871 PointsRewriteEngine On
RewriteRule ^pagename$ pagename.html
thanks guys, put the above code, but still doesn't work
will let you know any solution

robbrazier
6,524 PointsYou need to add [L]
to the end of the statement, hopefully that should fix it :)
So it'd be
RewriteEngine On
RewriteRule ^pagename$ pagename.html [L]

remimatia
2,871 PointsThanks Rob
it works even without the [L], but I need to write the links like this:
<li><a href="gallery">Photos</a></li>
is it ok? or it should work without removing the html extension??
thanks

robbrazier
6,524 PointsOh, I didn't realise that!
As far as I know it should work with and without the html extension

deletedaccount
5,089 PointsGlad that you figured it out Aldo, but it really doesn't make any difference for SEO whether you have the HTML extension or not. It does look cleaner though.
There's also an easier method, which is to create a subfolder, and put the HTML file inside that subfolder and name it index.html. This is what I do on my website, although I use the PHP extension.
Of course, you will need to remove the HTML extension from your href attributes for that to work.

remimatia
2,871 PointsThanks Charles, I didn't know that it doesn`t make any difference for SEO anyway, it looks better.
Thanks for the tip

remimatia
2,871 Pointsthanks for the link James