views:

153

answers:

5

If all CMS's (Drupal, MediaWiki) are just a collection of PHP or ASP in the background, then how do they display pages at www.site.com/directory/ or www.site.com/File_name without extensions or anything?

Is this some .HTACCESS configuration? Python? Perl? What could do this?

How could I do this for my server/websites? (Without using a CMS?)

+1  A: 

Look at the DirectoryIndex directive to change the default file to display for a directory, if you're using Apache.

CMSs tend to use URL re-writing to get user friendly URLs instead of having to have document ids on the URI.

Rowland Shaw
+6  A: 

You are after URL Rewriting. It enables the webserver to show content for URLs that do not map directly neither to the content present in the filesystem nor to a specific dynamic content handler (which are the two usually standard ways to serve content).

Vinko Vrsalovic
A URL matches the content served by definition. That's what Web servers do.
Rob Kennedy
+1  A: 

The paths without extension is something you set up at the webserver level. In IIS you can use wildcard application mapping. Basically then all requests go to the ISAPI extension you specify. In Apache you can use use Roland his suggestion.

Most of these type of applications also use a concept called URL Rewriting to have a different URL visible on the front-end then the one actually being handled by the webserver.

olle
+2  A: 

A web server is just a bit of software that listens for an incoming request, and when it gets one, it sends back some sort of response.

Traditionally, servers (e.g. Apache / IIS serving normal HTML files) would look at the incoming request, find the corresponding file on their local filesystem (e.g. for /home/about.html, they'll look in the home folder for a file called about.html), and send the contents of that file back to the client making the request. This is fast, lightweight and very easy to implement - but it is only one possible way to build a web server. Most web servers offer the ability to override this behaviour and do something much smarter with incoming requests.

What you need to do is configure your web server itself (IIS, Apache, lighttpd, whatever) to direct requests to a specific script or resource.

In IIS on Windows, there are two ways of achieving this.

The first is to configure IIS "Custom Errors" feature and map the 404 error page to, say, /MyCms/FindPage.asp - this means any time a client requests a page that isn't physically present, your web server will run that ASP page instead, and then inside that page, you can extract the original request URL (/home/info/events.html), look it up in a database or something, and return it. The client will be unaware this has happened.

For a more powerful alternative, you can use wildcard application mapping as suggested in olle's post - this will map EVERY request (not just the "not found" ones) to your CMS script or handler.

Dylan Beattie
+1  A: 

Most web servers have rewrite engines. Those allow you to rewrite/redirect certain requests internally or externally to other URLs.

For Apache there is the mod_rewrite module or the AcceptPathInfo directive which offers a similar functionality.

Gumbo