Get rid of .html file extensions

i have always coded with url links ending in .html but have noticed some sites having urls that end with / or just a word and not the file extension .html
how do i do this? (how do i get rid of the file extension)
cheers

I’m pretty sure it is called mod_rewrite. Check out the following links: one, [URL=“http://httpd.apache.org/docs/2.0/misc/rewriteguide.html”]two, [URL=“http://en.wikipedia.org/wiki/Rewrite_engine”]three, [URL=“http://www.workingwith.me.uk/articles/scripting/mod_rewrite”]four.

Hope this helps.

You can use mod_rewrite (as mentioned above) to create friendly URL’s through your .htaccess file, however if your website only has a limited amount of pages, you could name each file index.html and simply place it within folders which give the name of the directory structure they are navigating. :slight_smile:

Yes, but wouldn’t this create other problems, such as the CSS and images within in images folder in the root folder? Wouldn’t you then have to use absolute paths for everything rather than relative paths?

Forgive me if I’m wrong, as I am a beginner at this stuff.

Not always, you could use the base element in HTML to declare the base folder for everything (therefore allowing relative linking) or you could use htaccess to declare base directly so it would avoid this issue, while using mod_rewrite is a good solution and I would probably go with it myself I thought it best to offer the other solution which works too so the OP can determine what works best for them (after all, they may not be able to use htaccess) :slight_smile:

As I said, I’m a beginner!

Learn something new all the time :wink:

So you can put a.htaccess in a plain html site? Just curious I have only done it in php sites.

You can use htaccess on any site as long as its running apache and not windows. I use mod_rewrite all the time and its great at making sure the url’s look exactly how you want them to look. I wouldn’t worry about the .html extension… theres definetly no harm in having it there and can make your site look static rather than dynamic which historically has always looked good to search engines… although I think they are changing on this side of things being as most sites now are dynamic now in one way or another with content management systems being now so prevalent.

They work well because you can easily create a friendly link for any page although as pointed out here already you need to watch your image and link urls to ensure you either set a base url or code them in full…

Joe

thanks for all the good info guys i will look into it.
usually i would not bother with this and keep the .html extensions but im taking over a site that has its url’s setup without the extensions and i will have to keep it that way so as to not loose any links from other sites and generally not upset the SEO. everything will change if have the extensions on (as far as how the browser robots see it it will look like a new site and loose all rankings it has generated) or am i confused in thinking this?
cheers

It probably would cause a serious upset as the addresses to every link had changed, though it is better to have URL’s without the .html or whatever purely for the point of your visitors, do you think they know what the .html stands for? or even what extension they need to use? that is the main reason you should not use them, else you could end up with people thinking .php or .cfn or .jsp or .asp or .aspx or one of many other extensions should be what they need to type by default (even .htm) which means that all roads end in a 404 error - unless they guess right :slight_smile:

yes i agree. i want to do this the best (bullett proof) way. would that be the mod_rewrite way? and is this something a “good” hosting company would put in place for me and i write the code excluding the extensions?
im not sure how to go about this as it is all very new to me.
i appreciate all the advice
thanks

Basically any good hosting company will support the addition or editing of a .htaccess file, it is this file you will use to activate mod_rewrite by scripting in the appropriate Rewrite rules you want to take advantage of, if you Google the subject there are plenty of good articles on the subject of mod_rewrite, or as you want specifically, friendly URL’s :slight_smile:

Is this just a usuability issue? In my experience very little traffic comes from direct address typing… most is from bookmarks and search engines where the file extension is irrelevant because the visitor is simply selecting your link. html extension in that case is neither here or there…

If you really do want to change it then yes your ISP may be able to help with the htaccess file if they are nice! If not then this might help:-

workingwith.me.uk/articles/scripting/mod_rewrite

In terms of URLs changing the correct way to do this is 301 redirects for your old links which search engines will recognise as a page being moved and update the URL and pass any page rank along to the new page. This can also be accomplished in the htaccess file although I’ve found using 301 redirect and mod_rewrite together can cause conflicts.

Joe

for me it is not a usability issue it is more for the hundreds of links that have been created over the years to help establish good rankings and all these links are excluding extensions.
i do not want to break the already existing structure to which outside sites are linking.
also not leaving the url’s exactly the same i will loose all seo rankings when i put up the new site as the browser robots will not see it as the same site.
i am trying to keep content the same as to not confuse those pesky little robots but change the look and style of the site. (does that make sense?)

Got it! Now it all really depends on whether you want the search engines to update to the new URL and also old visitors to be automatically sent to the new URLs when they use old bookmarks etc.

Option 1… keep URLs exactly the same
Use mod_rewrite and the URL the search engines and visitors see will be the old one. Nothing really changes as only you know the new URLs… they are hidden from public view.

Option 2… redirect correctly to the new URLs
Use 301 redirect which will update search engines and redirect visitors using out of date bookmarks and links with no loss of ranking if its done properly.

More info here

stevenhargrove.com/redirect-web-pages/

HTH

Joe