tags:

views:

181

answers:

9

Hi devs!

I have seen urls like website.com/admin/ that don't actually show the "index.html" or file name after the last slash. How is this achieved?

Thank you!

+1  A: 

There is a configuration option on most web servers that allow the administrator to set one or more files to look for if the file-name isn't found. Often, they also let you set this on a directory by directory level.

Another possibility, depending on the site, is that it uses technology to convert (aka "rewrite") the URL on the fly so the URLs entered by the user are more meaningful to the user. This technique is common for sites built using the MVC templates.

JohnFx
+1  A: 

The webserver re-writes the URL to a real file (usually "index.html" or "default.html") in such situations.

msw
A: 

It depend on your http server (apache...) setting. It will for example automatically load your index.php if one exist in the directory.

EDIT:

By doing such setting, your browser will not change the address from http://site.com/ to http://site.com/index.html

Phong
Sweet, so what apache setting do I need to change to make the website.com/admin/ URL load a certain file "admin/filename.php" without actually showing the "filename.php" in the URL?
sharon
+1  A: 

The web server's configuration maps the URL to a resource. Most often that's a file such as index.HTML or index.php, but there doesn't have to be a file--the web server could be configured to serve the default index (or any other URL) by returning content generated by a module or cgi. There is no requirement for a one-to-correspondance between urls and files.

Devin Ceartas
A: 

It could be that default document is configured or the website is using MVC.

hallie
how MVC related to this?!?!?
zerkms
Check out MVC routing fundamentals -> http://www.asp.net/mvc/fundamentals/
hallie
A: 

Apart from the webserver doing some automagic file name guessing, it may be that there's a custom application running that handles URLs by itself. A URL is just a URL, mapping it 1:1 to a file name is just one way to do it.

deceze
+1  A: 

In addition to the default file (index.html, default.htm, default.aspx, ...) most webservers allow URL rewriting which means you can map any URL onto any resource. See Apache module mod_rewrite, or Windows Application and Request Routing, or ISAPI rewrite modules.

Hightechrider
A: 

There are at least three different ways...

  1. Use Default Documents
  2. Use URL Rewriting
  3. Use MVC
Rahul Soni
+2  A: 

A URL specifies the location of a resource, but that resource does not have to actually map to a physical file on the server. It's up to the server to decide how to process the URL and how to generate the resource to return.

Most webservers started by serving all the resources from files. Thus, most of the websites out there have their pages served as files, and the URLs they recognize have the corresponding form. If the website is still using a file-based webserver, it is possible to configure it to serve particular document by default, if a file is not specified.

However, lately, there's a big movement towards decoupling of the URLs and the actual files. Usually this is achieved through default documents (where the webserver is configured to serve specific file if the URL does not specify one), URL routing (where the webserver routes the request processing based on internal rules that map the incoming URL to the actual resources), URL rewriting (where the URL request is rewritten to a different URL before processing), or a combination of both.

In particular, the MVC frameworks rely a lot on the URL routing, as the URLs exposed by a web app based on an MVC framework specify not the location of a file on the server, both actually the code execution path for the web app. For example http://example.org/user/details/12345 would not specify the 12345 file in the /user/details folder, but would specify that the method Details on the class User should be invoked with parameter 12345 to generate the response.

Franci Penov
+1 for noting that URLs don't have to map to files. And a nice explanation as well :-)
Joey