Displaying items by tag: create redirection

Monday, 14 October 2013 00:00

Create a redirection rule

To create a redirection rule go to menu "Components" -> "ReDJ" –> "Redirects", and click on “New” button. A form will be shown to entering redirection information related to the rule.

ReDJ New Redirect

The "From URL" field must contains an "URL part" to match with any requested URL. If "Request only" is checked, then URL parts "scheme", "user", "pass", "host" and "port" will be ignored, otherwise the full requested URL will be checked. It is also possible to use Regular Expressions in "From URL" field. ReDJ supports regular expressions according to Henry Spencer's implementation:

http://dev.mysql.com/doc/refman/5.0/en/regexp.html

This option makes it possible to create complex patterns to match a bunch of URLs to redirect with just a single redirection rule.

The field "To URL" must contains the destination URL where to redirect the web browser for any requested URL that matches with the current rule. It must specify an absolute URL, starting with the "scheme" part. The "To URL" field can contains macros and placeholders to build the destination dynamically. Each macro or placeholder is evaluated after an URL matches, and its value is replaced to the macro or placeholder itself. Support of regular expressions, macros and placeholders allow to build complex URL trasformations.

The field "Skip" is optional. Like "From URL" it can contains an "URL part" and supports regular expressions, but its purpose is just the opposite. It allows to specify a condition to skip the rule and its redirect when the condition is satisfied.

The field "Skip user groups" works only for ReDJ Enterprise, and allows to select one or more user groups which skip the rule (i.e. the redirection will not be applied).

The "Redirect" field indicates the redirection type to use. There are three options available:

  • 301 (Moved Permanently)
  • 307 (Temporary Redirect)
  • 200 (Internal Redirect)

The Internal Redirect option is available only for ReDJ Enterprise, and allows to change the destination page returned to web browser "internally" to Joomla, on the server side. This means that the user stays on the same URL and cannot notice any changes in the address bar. The Internal Redirect option can be selected also in ReDJ Community, but in this case a standard 301 redirect will be used instead.

About the meanings of other fields:

  • Case sensitive: specifies if the match between "From URL" and the requested URL must consider the letters case (i.e. uppercase and lowercase are considered different). If case sensitive is checked, the rule must match with requested URL also for case of characters. If case sensitive is unchecked, no matter if rule and requested URL differ only for case of characters (i.e. MyPage.php = myPage.PHP = mypage.php).
  • Request only: as stated before, this field is used to specify if only the request part or the whole URL must be considered of the requested URL.
  • Decode URL: the requested URLs come on the server always encoded (i.e. special chars are replaced by % chars). If this field is unchecked the URL is compared with the rule as is. If the field is checked, the requested URL is first decoded and then checked if matches with the rule.
  • Placeholders: can contains a list of placehoders (one per row). A placeholder is like a variable that can assume a value based on any string, macros and other placeholders (defined before).
  • Comment: allows to add a memo note to each redirection rule.

The statistics fields provide useful information about rule usage. The "Hits" counts the number of times the rule were used, and the "Last visit" indicates the last time the rule were applied.

In the example showed in the image above, the source and the destination are:

From URL: ^/test.html
To URL: http://{siteurl}/

With this settings all the following URLs will be redirected:

http://www.mysite.com/test.html

http://www.mysite.com/test.html?param=xxx

http://www.mysite.com/test_html

While this will not be:

http://www.mysite.com/directory/test.html

This is because in the regular expression ^/test.html the initial caret ^ means "start with", and "request only" is checked, so /directory/test.html will not match. Notice that the URL with /test_html also matches, because the dot means "any char" in the regexp syntax. To specify a literal dot, this should be escaped with \, so the rule should be:

From URL: ^/test\.html

This will match only the first and the second URL of our previous example, but not the third (http://www.mysite.com/test_html).

The destination contains an example of macro, {siteurl}, which will be replaced with www.mysite.com.

Published in ReDJ for Joomla 2.5