为“漂亮”而设计网址

发布于 2024-10-14 02:12:16 字数 610 浏览 10 评论 0原文

我知道 mod_rewrite 方法可以将丑陋的 URL 转换为漂亮的 URL。我的问题是在此转换之前。

我还没有开发我的网站。我想设计所有页面,使漂亮的 URL 在服务器端也很漂亮。

我想为所有页面制定一个通用规则。通常所有页面都略有不同...

/news/12345                        =>    /news.php?id=1234
/members/Mikhail                   =>    /members.php?name=Mikhail
/subsection/page/banned-members    =>    /subsection/page.php?view=banned-members

在上面的三个示例中,每种情况下的 GET 变量名称都不同,第三个示例也可以开发为解释为 /subsection.php?file=page&view= banned-members

所以我的问题是:从设计的角度来看,我能做什么,在客户端和服务器端有一个优雅的解决方案来创建漂亮的 URL?

谢谢!

I'm aware of mod_rewrite methods to convert ugly URLs to pretty. My question is preceding this conversion.

I have not yet developed my website. I would like to design all pages such that the pretty URLs are also pretty on the server side.

I would like to come up with a general rule for ALL pages. Normally all pages are slightly different...

/news/12345                        =>    /news.php?id=1234
/members/Mikhail                   =>    /members.php?name=Mikhail
/subsection/page/banned-members    =>    /subsection/page.php?view=banned-members

In the three examples above the GET variable name is different for each case, and the third example could ALSO be developed to be interpreted as /subsection.php?file=page&view=banned-members

So my question is: What can I do, from the design point, do have an elegant solution on the client AND server side to create pretty URLs?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

邮友 2024-10-21 02:12:16

一般的经验法则是使用 url 的一部分来标识资源,并使用 GET 参数来对资源的呈现方式进行可选修改。

例如,对于用户配置文件 url:

/user/joe

/user/joe?showfull=1

两者都是相同的资源(用户配置文件),但后者指定如何呈现信息(显示有关用户的完整信息而不是默认金额)。

将此约定应用于上面的示例,我更愿意:

/news/12345
/members/Mikhail 
/subsection/page?view=banned-members

A general rule of thumb would be to use a portion of the url to identify resources, and GET parameters for optional modifications to how the resource is presented.

For example, for a user profile url:

/user/joe

and

/user/joe?showfull=1

Both the same resource (the user profile), but the latter specifies how to present the information (show full information about the user instead of the default amount).

Applying this convention to your examples above, I would prefer:

/news/12345
/members/Mikhail 
/subsection/page?view=banned-members
树深时见影 2024-10-21 02:12:16

在 PHP 中,一种可能的解决方案是使用一个中央 PHP 文件来处理站点的所有 URL。该脚本处理整个 URL 字符串并加载相关内容。它允许在 PHP 中完成各种重写或重定向。

In PHP, one possible solution is to have a central PHP file that processes all the URLs of the site. This script processes the whole URL strings and loads the relevant content. It allows all kinds of rewriting or redirecting to be done in PHP.

高冷爸爸 2024-10-21 02:12:16

使用 ASP.NET MVC 框架是“漂亮 URL”设计的典型代表

编辑:抱歉,没有注意到您的 PHP 文件...也有许多 PHP MVC 框架(尽管我对 URL 的外观没有任何经验)

Using the ASP.NET MVC framework is the poster-child of "pretty URL" designs

EDIT: Sorry, didn't notice your PHP files... there are a number of PHP MVC frameworks too (though I have no experience with how pretty the URLs look)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文