开发者

Which is better? mapping URLs to actual file structure or hiding them?

开发者 https://www.devze.com 2023-03-15 14:24 出处:网络
In Rails like frameworks, the URL is mapped to the folder structure (mostly) http://example.com/controller/method/id

In Rails like frameworks, the URL is mapped to the folder structure (mostly) http://example.com/controller/method/id

this means that, from the URL, one can guess there is a file fo开发者_Go百科r that controller, and it contains a method that renders the page (and id is the parameter). Is this good? or making the folder structure totally opaque from the URL structure is better?


Separating your URLs from your internal file structure is a good thing because it allows you to change the internal structure without affecting the interface (URLs).

Example from Wikipedia:

Another aspect of clean URLs is that they do not contain implementation details of the underlying web application. For example, many URLs include the filename of a server-side script, such as "example.php", "example.asp" or "cgi-bin". Such details are irrelevant to the user and do not serve to identify the content, and make it harder to change the implementation of the server at a later date. For example, if a script at "example.php" is rewritten in Python, the URL will have to change, or rewrite rules will need to be used to allow the old URL to redirect to the new one.

There are other advantages as well, such as that they are more human readable, easier to type, and play more nicely with search engines.

You might want to do some reading on search engine optimization (SEO): http://en.wikipedia.org/wiki/Search_engine_optimization and clean URLs: http://en.wikipedia.org/wiki/Clean_URL, especially the latter.

0

精彩评论

暂无评论...
验证码 换一张
取 消