Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
Why do forums use the url format:
www.domain.com/post/1234/Latest post

instead of something like this:

www.domain.com/post?&number?&Topic

I am working on a forum site and would have used the format 2.

I wish to know the reason for using format 1 and the principle behind it.It appears that what is stated by the url is the address of a folder and not that of a script or webpage.

I don't see the url ending with .php or .asp or .jsp so what process the request since it is not the address of a script.

How is the programming done?
Posted

1 solution

From a purely pragmatic point of view. It doesn't matter which approach you use.

The problem being solved by both methods is the ability target a page and pass in parameters.

Arguably using www.domain.com/post/1234/Latest is a more readable URL.

If you look into web frameworks such as MVC you see why/how these URLs are built up in the way that they are.

They implement a concept called routing. The following is an example:

C#
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

}


This example shows how the URL is built. The 1st part is the controller, the 2nd part is the action to apply and the 3rd is the id.

So for the following URL:

https://www.mydomain.com/customer/get/1234

You can see that you're accessing the customer controller and you're executing the get action on record 1234.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900