04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

easier urls<br />

140 Chapter 4<br />

I’d like my visitors to be able to<br />

type “http://www.starbuzzcoffee.com”<br />

and not have to type the “index.html”. Is<br />

there a way to do that?<br />

Yes, there is. One thing we haven’t talked about is what<br />

happens if a browser asks for a directory rather than a file<br />

from a Web server. For instance, a browser might ask for:<br />

http://www.starbuzzcoffee.com/images/<br />

or<br />

http://www.starbuzzcoffee.com/<br />

When a Web server receives a request like this, it tries to<br />

locate a default file in that directory. Typically a default file is<br />

called “index.html” or “default.htm” and if the server finds<br />

one of these files, it returns the file to the browser to display.<br />

So, to return a file by default from your root directory (or<br />

any other directory), just name the file “index.html” or<br />

“default.htm”.<br />

http://www.starbuzzcoffee.com<br />

it will change it to:<br />

But I asked about<br />

“http://www.starbuzzcoffee.com”,<br />

which looks a little different. It<br />

doesn’t have the ending “/”.<br />

Oops, you sure did. When a server receives a request like<br />

yours <strong>with</strong>out the trailing “/” and there is a directory <strong>with</strong><br />

that name, then the server will add a trailing slash for you.<br />

So if the server gets a request for:<br />

http://www.starbuzzcoffee.com/<br />

which will cause the server to look for a default file, and in<br />

the end it will return the file as if you’d originally typed:<br />

http://www.starbuzzcoffee.com/index.html<br />

Remember, when we’re<br />

talking about Web servers<br />

or FTP, we usually use the<br />

term “directory” instead<br />

of “folder.” But they’re<br />

really the same thing.<br />

The images directory in<br />

the root directory.<br />

The root directory itself.<br />

But, you need to find out<br />

what your hosting company<br />

wants you to name your<br />

default file, because it<br />

depends on the type of<br />

server they use.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!