X hide

How URL Manager works

From Plumrocket Documentation

You are viewing:  Url-manager-32.png  URL Manager

Example of Links Transformation

The Formation of Input Sequence

In order to simplify the explanation, we suggest comparing the rules of links formation to a set of colorful balls. Imagine that these balls are placed into a glass cylinder one by one as shown below. Each ball represents a particular part of the rule.

How-URL-Manager-works-1.png


This is the rule:

/red/($ball)/(green|blue)/($all)=> /green/$2/$3/

First, we will take into account only the input rule, i.e. the set of balls we want to find and transform in the future — /red/($ball)/(green|blue)/($all). This means that we want to get the following combination of balls: The red one stands for any color, the green or blue one stand for any number of balls of any color. Now we have to check the sequence of balls and make sure it is what we need. After we find the sequence that fits the rule, the processing will be launched. The balls on the picture below fit the rule, while the sequence above doesn't.

How-URL-Manager-works-2.png


Now, let's take the cash register with compartments for different banknotes as an example. Let's number these compartments and place a ball (in the parentheses) into each of them. For example, ($ball) stands for one ball of any color, (green|blue) stands for a green or blue ball, ($all) stands for indefinite number of balls of any color. Have a look at these compartments:


How-URL-Manager-works-3.png


Now, let's analyze each ball and place the balls into compartments. The first ball is red. That's what we said - "the first ball should be a red one". The rule was "a ball not in parentheses", that's why we skip it. If we said «/(red)/», we would place the red ball into the compartment, since the rule of the parentheses would be executed. It is simple: if there are parentheses, the ball should be placed into the compartment, if there are no parentheses, the ball should be left out. The second ball is yellow. The rule is - the second ball can be of any color. That's what we said: ($ball). Since there were parentheses in the rule, we should place this ball into the first compartment - the rule of the first parentheses and the first variable element is executed. This is what we get:


How-URL-Manager-works-4.png


The third ball should be either green or blue The rule requires the parentheses too. That's why we should place the third ball into the second compartment. /red/($ball)/(green|blue)/($all)


How-URL-Manager-works-5.png


The next rule was "indefinite number of balls of any color". Thus, all the remaining balls fit the rule. (Look at the picture below.)


How-URL-Manager-works-6.png


Let's place the balls into the corresponding compartments and check the result below:


How-URL-Manager-works-7.png


The Formation of Output Sequence

Now, we should form the output sequence. Let's form the sequence according to the second part of the rule. Check our example:

/green/$2/$3/

It is simple, since we don't have to check the balls anymore - we can form the sequence ourselves. We want the green ball to be the first one:


How-URL-Manager-works-8.png


The next ball is $2. This means that we need the ball from the second compartment. There is a green ball - it will be added next.


How-URL-Manager-works-9.png


Then we have to fill in the third compartment ($3). There are several balls in the third compartment due to the rule ($all). We should take them all, and get the following sequence:


How-URL-Manager-works-10.png


This is how you can transform the input sequence that the system cannot read (on the left) into a resulting sequence (on the right)


How-URL-Manager-works-11.png How-URL-Manager-works-12.png


This example can serve to better understand our Extension: the balls are like nodes, the compartments are like links, words between the slash marks: /customer/account/create => customer, account, create. Now, you can try to understand the real URL Manager rule. For instance:

/profile/($node)/($node)/($all) => /customer/account/$1/param/$2/?other=$3.

The input address is /profile/create/2/. We want to create an account adding some parameter to it. Let's check whether it fits the rule: the first word should be profile, then goes any word (the word should be treated here as a set of symbols between «/»), one more word, and then - any symbols (or nothing). Let's analyze the address. We have three balls: profile, create, 2. The first ball (profile) should be ignored, since it goes without parentheses in the rule. The next ball in the rule is ($node) which stands for one word. We check and fill the corresponding compartment: 1: create The following parentheses require a word. 1: create 2: 2 The third parentheses require the indefinite number of symbols (words, balls). We check the address again and see that there is nothing left. So, the third compartment will be empty: 1: create 2: 2 3:

Now we look at the rule of output address formation:

/customer/account/$1/param/$2/?other=$3

Instead of $1 we place the content of the first compartment; instead of $2 we place the content of the second compartment etc. The result is as follows:

/customer/account/ + create + /param/ + 2 + /?other= => /customer/account/create/param/2/?other=

This is how the address convenient for a customer /profile/create/2/ can be transformed into the address that the system can read: /customer/account/create/param/2/?other=. It can be visualized as shown on the scheme below:

How-URL-Manager-works-schema-1.png

Example of Links Formation

Imagine, there is a rule:

/profile/($node)/($node)/($all) => /customer/account/$1/param/$2/?other=$3.

We replace the parentheses on the left with corresponding elements on the right.

/profile/$1/$2/$3 => /customer/account/($node) /param/($node) /?other=($all).

we also replace the parts of the rule:

/customer/account/($node) /param/($node) /?other=($all) => /profile/$1/$2/$3.

Now, if we have the input link from the system (not from the customer):

/customer/account/create/param/2/?other=test,

we repeat the actions we have previously taken:

1: create 2: 2 3: test

and form the output link:

/profile/ + create + / + 2 + / + test => /profile/create/2/test,

which will replace the previous one all over the website. You can check the direct transformation algorithm above to make sure that the link we get totally corresponds to the one in the example.


Navigation