为什么论坛使用这种网址格式? [英] Why do forums use this url format?

查看:110
本文介绍了为什么论坛使用这种网址格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么论坛使用网址格式:

www.domain.com/post/1234/最新帖子



而不是某些东西像这样:



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



我正在努力一个论坛网站,并将使用格式2.



我想知道使用格式1的原因及其背后的原理。它似乎是由url是文件夹的地址,而不是脚本或网页的地址。



我看不到以.php或.asp或.jsp结尾的url所以请求处理的是什么,因为它不是脚本的地址。



如何完成编程?

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?

推荐答案

从纯粹务实的角度出发。使用哪种方法无关紧要。



两种方法解决的问题是能够定位页面并传入参数的能力。



可以使用www.domain.com/post/1234/Latest是一个更易读的URL。



如果你看看网络像MVC这样的框架,你可以看到为什么/如何以它们的方式构建这些URL。



他们实现了一个名为routing的概念。以下是一个例子:



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:

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
    );

}





此示例显示了URL的构建方式。第一部分是控制器,第二部分是应用的动作,第三部分是id。



因此对于以下URL:



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



你可以看到你正在访问客户控制器,您正在执行记录1234上的获取操作。



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.


这篇关于为什么论坛使用这种网址格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆