PDA

View Full Version : Get rid of .html in url?




andyjamesnelson
Sep 22, 2008, 07:12 AM
Hey I want to know how I can get rid of the .html extension in a url?

For example my site address is: andyjamesnelson.co.uk

I saved another file into my directory called beatabet.html.

I thought I would be able to type: andyjamesnelson.co.uk/beatabet and it would load the page but it doesn't it only loads if I add the.html

Is there an easy way to get around this? I'm pretty sure one should try and keep urls as simple and short as possible.

If you could help me out that would be ace. Thanks. Andy



sammich
Sep 22, 2008, 07:27 AM
By default when you type in a URL for a website, the looks for a 'index' file. Whether that ends in html, php, asp. For example:

http://www.apple.com/index.html
is the same as
http://www.apple.com/

If you want to have http://www.andyjamesnelson.co.uk/beatabet to work then make a new directory on the server called 'beatabet' and put your index.html in there.

andyjamesnelson
Sep 22, 2008, 07:51 AM
Ok I get that - but you really have to make a new directory for each address if you don't want to have the html extension in the url? That seems extreme?

Andy

design-is
Sep 22, 2008, 07:58 AM
Its the only way I know of... its not a lot of extra effort to bung each page in its own folder.

SrWebDeveloper
Sep 22, 2008, 08:42 AM
@andyjamesnelson:

It also keeps your content well organized. Especially if alot of content is involved, folders is a good thing.

Of course there is a concept called friendly URL's which is documented here (http://www.surefirewebservices.com/blog/php/friendly-url-tutorial-01) you might want to explore if you run Apache and have mod_rewrite enabled. It's a misconception people do that for security concerns or redirects (untrue), but use the examples to create your own rules to replace extensions with whatever you want and parse the arguments in your code accordingly. Google around for 'friendly url' for other examples.

You could also use this method if you wanted all your content in one folder but custom arguments associated with each task, i.e. http://www.yourdomain.com/contactus or http://www.yourdomain.com/gallery/1/category/2/filename.mp3 where the first displays a contact us form and the second ties into a gallery script where gallery and category number and media file name are passed to it, but all live in your document root if you wish.

Modern CMS's such as Drupal and Joomla also have options to enable friendly URL's if it's supported server side.

-jim