Home > Backend Development > PHP Tutorial > Understanding URLs

Understanding URLs

WBOY
Release: 2016-07-29 09:05:31
Original
1274 people have browsed it

Understanding of URL

Wikipedia gives the answer

URL (full name Uniform Resource Locator), also translated as Uniform Resource Locator, commonly known as web page address (website), is the address of a standard resource on the Internet. To go anywhere on the Internet, you need its URL.

First of all, we need to understand the meaning of resource positioning. When we configure and deploy web servers, we should have seen the document root configuration item. Taking nginx as an example, in nginx, we need to configure a root option. , and each server corresponds to a server_name, or a domain name, or an IP, or an identifier. In fact, this server_name can be simply regarded as an alias of root. When this server_name is accessed, it will automatically Search under the root directory. For example:

<code>server {
    server_name test.com
    root /htdocs
    # some config
}</code>
Copy after login

When visiting http://test.com, it will go to the /htdocs directory to find the target.

http://test.com/a.html => /htdocs/a.html
http://test.com/public/a.html => /htdocs/public /a.html

This is the most basic method. Of course, you can configure others in the server, which will not be explained here.

In fact, to put it bluntly, it just plays the role of "resource positioning".

Obviously, what we are looking for here is html files, you can also look for json, xml files, such as:

http://test.com/a.json => /htdocs/a.json
http://test.com/public/a.xml => /htdocs/public/a.xml

In fact, they are all the same. As long as you understand "resource positioning", then in fact, the URL is access As for the content of a file, how this "file" is executed internally needs to be defined by yourself.

Http Api Design

Now that you understand the meaning of the above URL, it is easy to design the API. The so-called RESTful API design, in fact, my understanding is nothing more than to make you clear the role of the URL, and then give it accordingly Different "files" to operate on.

1. Obtain articles:

Host: http://test.com

1.1 Article list
<code>http://test.com/articles/{page}

http://test.com/articles/1
http://test.com/articles/2</code>
Copy after login
1.2 Article details
<code>http://test.com/articles/{page}/{id}.{format}

http://test.com/articles/1/3.html
http://test.com/articles/2/12.json</code>
Copy after login

The above is understood as:

http://test.com/articles/1 /3.html This address locates: /htdocs/articles/1/3.html
http://test.com/articles/2/12.json This address locates: /htdocs/articles/2/12.json

It’s easy to understand. The API designed in this way can actually be collected at a glance. You can define the resource suffix yourself. For example, FastD has this function, which can return different content formats according to different suffixes.

The above is just my personal understanding and thoughts, please give me feedback and criticism.

The above introduces the understanding of URL, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template