扩展网址如何工作 [英] How do extended urls work

查看:45
本文介绍了扩展网址如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这些类型的 URL 如何加载页面......基于它们的 GET 参数.

I know how these kind of URLs load the page ... based on their GET parameter.

http://www.bedupako.com/songs.php?page=show_song_details.php&songid=1167&n=0&back=no

在后端大致是这样的:

<?php
switch($_GET['page']) {
case 'xx': include('my page');break;
.
.
.
default: include('default');break;
}
?>

但是这些类型的 URL 是如何工作的呢?我的意思是,数据是如何动态加载的?

But how do these kinds of URLs work? I mean, how is the data loaded dynamically?

www.dummysite.com/parm/subpage1/xyz
www.dummysite.com/parm/subpage2/xyz

如何解析这些类似于网站的 GET 参数?

How are these parsed similar to the GET param like websites?

推荐答案

你可以按照其他人的建议单独使用 mod_rewrite,但大多数站点不这样做,因为它不是很灵活,如果你有的话,维护起来会很烦人不止几个这样漂亮"的网址.

You can use mod_rewrite by itself as others have suggested, but most sites do not do this because its not very flexible, and can be annoying to maintain if you have more than a couple of these "pretty" URLS.

相反,他们设置了一个基本的重写规则,将所有内容转发到单个 index.php,然后在应用程序端,他们根据定义的模式解析 URI - 这些称为路由".路由解析通常发生在某种路由类中,该类处理定义的路由并将它们与 URI 进行比较,然后在找到匹配项时解析出匹配路由的参数.

Instead they set up a basic rewrite rule to forward everything to a single index.php and then on the application side they parse the URI based on defined patterns - these are called "routes". Route parsing usually happens in some kind of routing class which process the defined routes and compares them to the URI, and then when it finds a match parses out the parameters for the matched route.

这些都提供了很好的路由器示例,但是如果没有其他交互类,它们很难理解:

These all provide good examples of a router, but they are hard to understand without the other interacting classes:

这篇关于扩展网址如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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