How do extended urls work

和自甴很熟 提交于 2020-01-13 16:30:15

问题


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

and in the back-end roughly something like this:

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

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

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


回答1:


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.

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:

  • Zend: Zend_Controller_Router_Rewrite
  • Symfony: sfPatternRouting
  • Cake: Router
  • CodeIgniter: CI_Router



回答2:


In most cases this will be handled by the web server on-the-fly according to a set of rules. The specifics of it will vary from server to server and on a case-by-case basis. In Apache it is usually done using the mod_rewrite extension.




回答3:


You should look at http://httpd.apache.org/docs/2.0/misc/rewriteguide.html url rewriting if you're with apache (most likely)



来源:https://stackoverflow.com/questions/6968034/how-do-extended-urls-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!