ReDJ for Joomla 2.5

ReDJ for Joomla 2.5 (13)

ReDJ for Joomla 2.5

This feature allows to record all the referers for site visitors. A trace log with all referers is available, and this can be useful to identify traffic sources for the web site.

ReDJ referers

For any referer item in the list the following fields are available:

NameValueDescription
Visited URL Text Absolute URL visited by users (e.g. http://www.yoursite.com/trackme.html).
Referer URL Text Absolute URL of the referer site where the user comes from (e.g. http://www.myfriend.com/linktome.html).
Domain Text This field reports just the domain part for the referer site URL (e.g. www.myfriend.com).
Hits Integer Number of times the referer URL was detected for the visited URL in site’s visits.
Last Visit Datetime This field reports the timestamp for the last time which referer URL was detected for the visited URL in site’s visits. This is useful to check active referer URLs.

About the available buttons:

ReDJ referers buttons

Purge button will delete all entries.

Delete button will delete only selected entries.

Reset stats will just reset all statistics (hits and last visit).

Beware that this feature must be activated with a corresponding option in the plugin settings. See paragraph “ Plugin settings” for more details.

In this paragraph we will explain the meaning of each plugin parameter. To edit plugin settings go to menu "Extensions" -> "Plug-in Manager", find "System - ReDJ Community" or "System - ReDJ Enterprise" in the list and click on it to access to configuration page.

Basic Plugin Parameters

ReDJ basic plugin settings

In the following table there’s a list of all basic plugin parameters.

NameValueDescription
Custom page 404 No/Yes No, disables. Yes, replace Joomla standard error page with a custom one.
Page 404 Drop-down list Allows to select the custom error page to use. Pages can be created under the ReDJ component, section "Pages 404". The page is used only when "Custom page 404" option is set to Yes.
Track errors No/Yes No, disabled. Yes, enable errors trace for site URL calls (trace data are visible under ReDJ component).
Track referrers No/Yes No, disabled. Yes, enable referers trace from site visitors (trace data are visible under ReDJ component).
Referers to exclude Text List of domains to ignore when tracing referers from site visitors, one per row (e.g. www.google.com). The following macros are also available and can be indicated each one on a single row: {self} to exclude the own domain (i.e. internal referer), {none} to exclude visits without referer.
Redirect any error No/Yes No, disabled. Yes, redirect any error call, that don’t match with any (active) redirect item, to a common destination page. Beware that this also replace the custom error 404 page, just because no more error 404 can be obtained from site calls.
Redirect URL Text Absolute URL where to redirect all the errors with a 301 return code (e.g. http://www.google.it). The URL is used only when "Redirect any error" option is set to Yes, and only if none of the enabled items match with the error URL (i.e. after redirect phase). A {siteurl} macro is also supported here.

Advanced Plugin Parameters

ReDJ advanced plugin settings

In the following table there’s a list of all advanced plugin parameters.

NameValueDescription
Shortcut extensions Text List of comma separated file extensions to drop on error page for 404 error (e.g. gif,jpg,jpeg,png). This can be useful, as example, to avoid the full redirect process for each call to a non-existing image.
Base path Text The web site base installation path (e.g. /myportal if the site's homepage is http://www.mysite.com/myportal). This string will be dropped from any request before to check redirection rules. This increase portability for configured items. Leave blank if the site is installed on the root.

These are some of the common questions posted on support forum.

How toSolution
Match only site’s homepage:
http://www.mysite.com/

Create an item as follow:

From URL: ^/$
Request only: true (checked)

The expression means “start with (^) and end with ($) slash (/)” (i.e. there’s ONLY the slash).

Match an URL with one or more parameters:
http://www.mysite.com/catalog.php?page=1&order=asc

Create an item as follow:

From URL: /catalog\.php\?page=1&order=asc

Or:

/catalog\.php[[.question-mark.]]page=1&order=asc

In both cases you need to "escape" special chars like the question mark (?) or the dot (.) as you need them "literal". You can do it with a backslash (\) behind, (or using special strings like "[[.question-mark.]]").

Match with a single rule all the URLs like the following:

/index2.php?option=com_content&task=view&id=159&pop=1&page=52&Itemid=10218
/index2.php?option=com_content&task=view&id=17&pop=1&page=0&Itemid=72
/index2.php?option=com_content&task=view&id=301&pop=1&page=0&Itemid=10440
/index2.php?option=com_content&task=view&id=77&pop=1&page=0&Itemid=113
...

Create an item as follow:

From URL: /index2\.php\?option=com_content&task=view&id=[0-9]{1,3}&pop=1&page=[0-9]{1,2}&Itemid=[0-9]{1,5}

The expression [0-9]{1,5} means "a sequence from 1 to 5 digits".

Redirect from an old folder to a new one:

Old structure: http://www.mysite.com/category/oldfolder/anything

New structure: http://www.mysite.com/category/newfolder/anything

Create an item as follow:

From URL: ^/category/oldfolder/
To URL: {scheme}://{siteurl}/category/newfolder/{pathltrim /category/oldfolder/}{queryfull}
Request only: true (checked)

Referring to an URL like the following:

ReDJ URL parts

Here is a list of supported macros for destination "To URL" field:

MacroDescription
URL macros
{siteurl} Web site address
Example

www.example.com/path/to/Joomla

{scheme} URL scheme
Example

http

{host} URL host
Example

www.example.com

{port} URL port number
Example

8080

{user} User name
Example

fredbloggs

{pass} User password
Example

itsasecret

{path} URL path
Example

/path/to/Joomla/section/cat/index.php

{query} URL query string
Example

task=view&id=32

{queryfull} URL query string full (with question mark)
Example

?task=view&id=32

{querybuild var1=value1,...,varN=valueN} Builds URL query containing only specified variables. If a value is specified for a variable, this is assigned to the variable
Example

{querybuild id,task} => id=32&task=view
{querybuild id,task=edit} => id=32&task=edit
{querybuild id,task=view,ItemId=12} => id=32&task=view&ItemId=12

{querybuildfull var1=value1,...,varN=valueN} Same as 'querybuild' but with question mark
Example

{querybuildfull id,task} => ?id=32&task=view
{querybuildfull id,task=save} => ?id=32&task=save
{querybuildfull id,task,action=close} => ?id=32&task=view&action=close

{querybuildappend var1=value1,...,varN=valueN} Same as 'querybuild' but with ampersand
Example

{querybuildappend id,task} => &id=32&task=view
{querybuildappend id,task=save} => &id=32&task=save
{querybuildappend id,task,action=close} => &id=32&task=view&action=close

{querydrop var1=value1,...,varN=valueN} Builds URL query removing specified variables from the original query. If a value is specified for a variable, this is assigned to the variable (that is not dropped) - ENTERPRISE VERSION ONLY
Example

{querydrop task} => id=32
{querydrop id,task=edit} => task=edit
{querydrop id,task=save,action=close} => task=save&action=close

{querydropfull var1=value1,...,varN=valueN} Same as 'querydrop' but with question mark - ENTERPRISE VERSION ONLY
Example

{querydropfull task} => ?id=32
{querydropfull id,task=save} => ?task=save
{querydropfull id,task=edit,action=close} => ?task=edit&action=close

{querydropappend var1=value1,...,varN=valueN} Same as 'querydrop' but with ampersand - ENTERPRISE VERSION ONLY
Example

{querydropappend task} => &id=32
{querydropappend id,task=save} => &task=save
{querydropappend id,task=edit,action=close} => &task=edit&action=close

{queryvar varname,default} Returns the current value for the variable 'varname' of the URL, or the value 'default' if 'varname' is not defined (where default = '' when not specified)
Example

{queryvar task} => view
{queryvar id} => 32
{queryvar maxsize,234} => 234

{requestvar varname,default} Returns the current value for the variable 'varname' of the request, no matter about method (GET, POST, ...), or the value 'default' if 'varname' is not defined (where default = '' when not specified)
Example

{requestvar id} => 32
{requestvar limit,100} => 100

{authority} URL authority string
Example

fredbloggs:itsasecret@www.example.com:8080

{baseonly} Returns the base path only (empty when installed on root, i.e. it will never contains a trailing slash)
Example

/path/to/Joomla

{pathfrombase} Returns the path without the base part
Example

/section/cat/index.php

{pathltrim pathtotrim} Strip the string specified (pathtotrim) from the beginning of the path and returns the result
Example

{pathltrim /path/to} => /Joomla/section/cat/index.php

{pathrtrim pathtotrim} Strip the string specified (pathtotrim) from the end of the path and returns the result
Example

{pathrtrim /index.php} => /path/to/Joomla/section/cat

{pathfrombaseltrim pathtotrim} Same as 'pathltrim' but works on path without the base part - ENTERPRISE VERSION ONLY
Example

{pathfrombaseltrim /section} => /cat/index.php

{pathfrombasertrim pathtotrim} Same as 'pathrtrim' but works on path without the base part - ENTERPRISE VERSION ONLY
Example

{pathfrombasertrim index.php} => /section/cat/

{preg_match N}pattern{/preg_match} Returns the N-th matched pattern on the 'full source URL', where N = 0 when not specified - ENTERPRISE VERSION ONLY
Example

{preg_match}/([^\/]+)(\.php|\.html|\.htm)/i{/preg_match} => index.php
{preg_match 2}/([^\/]+)(\.php|\.html|\.htm)/i{/preg_match} => .php

{routeurl} Returns the routed (relative) URL using all current variables
Example

/using-joomla.html

{routeurl var1,var2,var3=myvalue,..,varN} Returns the routed (relative) URL for specified variables
Example

index.php?var1=value1&var2=value2&var3=myvalue&..&varN=valueN

{pathfolder N} Returns the N-th folder of the URL path - ENTERPRISE VERSION ONLY
Example

{pathfolder 4} of /path/to/Joomla/section/cat/index.php => section

{pathfolder last-N} Returns the (last-N)-th folder of the URL path, where N = 0 when not specified - ENTERPRISE VERSION ONLY
Example

{pathfolder last-1} of /path/to/Joomla/section/cat/index.php => cat

Site macros
{sitename} Global site name
Example

Global $sitename configuration value

{globaldescription} Global site meta description
Example

Global $MetaDesc configuration value

{globalkeywords} Global site meta keywords
Example

Global $MetaKeys configuration value

{username} Returns the current username
Example

{username} => admin

{username default} Returns the current username or the value 'default' for guest users
Example

{username nobody} => nobody

{userid} Returns the current user ID
Example

{userid} => 62

{userid default} Returns the current user ID or the value 'default' for guest users
Example

{username 1001} => 1001

Database macros
{tableselect table,column,key}value{/tableselect} Returns result of a SQL query (SELECT column FROM table WHERE key = value). Support #__ notation for table name
Example

{tableselect #__users,username,id}135{/tableselect} => SELECT username FROM #__users WHERE id = 135

{preg_select table,column,key,N}pattern{/preg_select} Same as 'preg_match' but uses the matched result to execute a SQL query (SELECT column FROM table WHERE key = matchN). Support #__ notation for table name - ENTERPRISE VERSION ONLY
Example

{preg_select #__content,title,id,1}/id=([0-9]+)/i{/preg_match} => SELECT title FROM #__content WHERE id = 32

{placeholder_select table,column,key1=placeholder1,..,keyN=placeholderN} Returns result of a SQL query (SELECT column FROM table WHERE key1 = ${placeholder1} AND ... AND keyN = ${placeholderN}) where ${placeholderN} is the value of the placeholder with name placeholderN. Support #__ notation for table name. The 'placeholder' must be previously defined (just placeholder name needed, not ${} format) - ENTERPRISE VERSION ONLY
Example

userId=62
{tableselect #__users,username,id=userId} => SELECT username FROM #__users WHERE id = 62

String macros
{substr start,length}text{/substr} Returns the portion of string specified by the start and length parameters. String are zero-based (i.e. first char has index 0)
Example

{substr 1,3}Joomla{/substr} => oom

{strip_tags}text{/strip_tags} Strip HTML and PHP tags from the given string
Example

{strip_tags}<p>hello<br/>Joomla</p>{/strip_tags} => helloJoomla

{extract N}text{/extract} Returns the Nth sentence delimited with carriage return (DOS, UNIX or MAC format). All HTML tags stripped
Example

{extract 1}<p>This is a sentence.\nAnd this is another one.</p>{/extract} => This is a sentence.

{extractp N}text{/extractp} Returns the Nth HTML paragraph <p></p>. All HTML tags stripped
Example

{extractp 2}<p>First paragraph</p><p>Second paragraph</p><p>Third paragraph</p>{/extractp} => Second paragraph

{extractdiv N}text{/extractdiv} Returns the Nth HTML paragraph <div></div>. All HTML tags stripped
Example

{extractp 3}<div>First paragraph</div><div>Second paragraph</div><div>Third paragraph</div>{/extractp} => Third paragraph

{preg_subject N,subject}pattern{/preg_subject} Returns the N-th matched pattern on the 'subject', where N = 0 when not specified. The 'subject' can contain placeholders, but cannot contain standalone '}' chars - ENTERPRISE VERSION ONLY
Example

{preg_subject 2,First/Second/Third}/([^\/]+)\/([^\/]+)\/([^\/]+)/i{/preg_subject} => Second

{preg_placeholder N,placeholder}pattern{/preg_placeholder} Returns the N-th matched pattern on the 'placeholder' evaluated string, where N = 0 when not specified. The 'placeholder' must be previously defined (just placeholder name needed, not ${} format)
Example

a=First/Second/Third
{preg_subject 2,a}/([^\/]+)\/([^\/]+)\/([^\/]+)/i{/preg_subject} => Second

{lowercase}pattern{/lowercase} Returns the pattern in lower case
Example

{lowercase}ALL to Lower{/lowercase} => all to lower

{uppercase}pattern{/uppercase} Returns the pattern in upper case
Example

{uppercase}ALL to UppeR{/uppercase} => ALL TO UPPER

{urldecode}pattern{/urldecode} Returns the decode pattern using urldecode() function
Example

{urldecode}%2Fgoto%20home%2F{/urldecode} => /goto home/

{urlencode}pattern{/urlencode} Returns the encoded pattern using urlencode() function
Example

{urlencode}/encode me/{/urlencode} => %2Fencode%20me%2F

{rawurldecode}pattern{/rawurldecode} Returns the decode pattern using rawurldecode() function
Example

{rawurldecode}foo%20bar%40baz{/rawurldecode} => foo bar@baz

{rawurlencode}pattern{/rawurlencode} Returns the encoded pattern using rawurlencode() function
Example

{rawurlencode}foo @+%/{/rawurlencode} => foo%20%40%2B%25%2F

{str_replace search,replace}pattern{/str_replace} Returns the pattern after replacing 'search' with 'replace'
Example

{str_replace john,scott}my name is john{/str_replace} => my name is scott

ReDJ allows to create a custom error page that can replace the Joomla standard one. To manage error pages go to menu "Components" -> "ReDJ" -> "Pages 404".

ReDJ Pages 404

There are always two predefined pages as default, with titles "Italiano" (ID = 1) and "English" (ID = 2). These are example pages, added just to show how to create HTML for a custom error page. Specifically, these pages are identical to Joomla standard error page, except they add the email address of site Administrator, showing how to use supported macros.

BEWARE: do NOT customize these pages, because these are deleted and recreated on each ReDJ upgrade, so any changes will be lost. It’s better to add a new page (ID > 2) and use this.

For any custom error page the following fields are available:

NameValueDescription
Title Text The title to identify the custom error page.
Language Name Text The language identifier for the custom error page.
Page Text Insert HTML code of the custom error page. The following macros can be used:
  • {siteurl} Site web address
  • {sitename} Web site name
  • {sitemail} Address used to send site mails
  • {fromname} Name used to send site mails
  • {errormessage} Description message of occurred error
  • {article ID} Include an article (intro and fulltext). Replace "ID" with content item ID to include
Hits Integer Number of times the custom error page were used (i.e. returned to site visitors).
Last visit Date Last time the custom error page were used.

Once a custom error page was created, it can be enabled in ReDJ system plugin. Select menu "Extensions" -> "Plug-in Manager" and open plugin "System - ReDJ Community" or "System - ReDJ Enterprise". Under "Basic Options" set "Custom page 404" to yes and select the page to use from the drop-down list. See paragraph "Plugin settings" for more details.

ReDJ Plugin Page 404

With this function it is possible to record all errors that the site receives. This provide a kind of trace log for error requests, and can be useful to identify dead backlinks that need to be redirected elsewhere. Analyzing requests it is also possible to extract other useful information (e.g. to detect if the site is subject to hacker attacks like remote file inclusion or sql injection).

ReDJ errors

For any error item recorded the following fields are available:

NameValueDescription
Visited URL Text Absolute wrong URL called by users (e.g. http://www.yoursite.com/an-old-page.html).
Error Code Integer The error code generated by Joomla for the page (usually 404 – Not Found).
Hits Integer Number of times the wrong URL was called by users.
Last Visit Datetime This field reports the timestamp for the last time which wrong url was called by an user. This is useful to check if the problem is solved by a redirection (in this case, the timestamp doesn't change anymore).
Last Referer Text This field reports the site referer for the last request of the wrong url. This is useful to identify which sites has dead backlinks to your pages.

About the available buttons:

ReDJ errors buttons

Purge button will delete all entries.

Delete button will delete only selected entries.

Reset stats will just reset all statistics (hits and last visit).

Beware that this feature must be activated with a corresponding option in the plugin settings. See paragraph “ Plugin settings” for more details.

Version 1.9.3:

  • Fixed REGEP BINARY query error with MySQL 8.

Version 1.9.2:

  • Fixed URLs and links for Joomla! 3.9.x.

Version 1.9.1:

  • Fixed an issue with seterror function;
  • Added support for https to custom error page of type link.

Version 1.9.0:

  • Added macros {camelcase} and {ucwords};
  • Added support for Joomla! Update System.

Version 1.8.3:

  • Fixed an issue with empty function (return value in write context);
  • Added an option to apply a rule only in case of error (sponsored by damago gmbH).

Version 1.8.2:

  • Fixed an issue with shortcut extensions.

Version 1.8.1:

  • Fixed an issue with exception handler for Joomla 3.6.0;
  • Improved error management.

Version 1.8.0:

  • Fixed an issue with exception handler;
  • Changed some code for PHP 7 compatibility.

Version 1.7.10:

  • Fixed and issue with exception handler.

Version 1.7.9 (only for J3):

  • Fixed an issue with pagination;
  • Fixed an issue with {requestvar};
  • Added macro {placeholder_insert} (only for Enterprise);
  • Added macro {placeholder_update} (only for Enterprise).

Version 1.7.8:

  • Fixed an issue with filter in search tools on errors and redirects;
  • Improved route_url() function;
  • Fixed an issue with drop_query_vars() function.

Version 1.7.7:

  • Fixed code for PHP 5.5 deprecated preg_replace /e modifier;
  • Fixed issue with {queryvar} macro;
  • Fixed issue with {substr} macro;
  • Added macro {pathfolder} (only for Enterprise).

Version 1.7.6:

  • Fixed an issue with exceptions management (call_user_func and variable passed by reference).

Version 1.7.5:

  • Added macros {urlencode} and {urldecode};
  • Improved function sanitizeURL for UTF-8 support when multibyte library is missing;
  • Added a redirect URL for each error URL;
  • Added a clean function for errors which saves errors with a redirect attached (unlike the purge function);
  • Fixed an issue with {username} and {userid} macros;
  • Added macros {rawurldecode} and {rawurlencode};
  • Added macro {str_replace};
  • Removed a wrong check on document type inside onAfterInitialise;
  • Added skip_usergroups feature to skip rules for specified groups of users (only for Enterprise);
  • Added macro {placeholder_select} (only for Enterprise).

Version 1.7.4:

  • Changed the interface to support new filters and ordering (only for J3);
  • Fixed an issue related to changes of JUri behavior (only for J3);
  • Fixed an issue of compatibility of plugin with PHP 5.2.

Version 1.7.3:

  • Fixed an issue with rule search filter;
  • Fixed an issue with errors search filter, pages 404 and referers (only for J3);
  • Fixed an issue on the custom error page (when the option is enabled but page is not selected);
  • Improved macro {routeurl} for the unwanted variables removal;
  • Improved function to manage redirect of all errors;
  • Improved interface to manage errors and referers;
  • Added new URL macros {queryappend}, {querybuildappend}, and {querydropappend};
  • Added new site macros {username}, {userid};
  • Added new string macros {lowercase}, {uppercase};
  • Added rule condition to skip redirect;
  • Added button to reset statistics (hits and last visit);
  • Fixed an issue in the package related to plugin uninstall.

Version 1.7.2:

  • Improved trim text function;
  • Improved queryfull macro;
  • Added "shortcut extensions" option to plugin;
  • Created installation package;
  • First release for Joomla 3.0.

Version 1.7.1:

  • Fixed issue with custom error page;
  • Added combobox selection for the custom error page.

Version 1.7.0:

  • Added support for placeholders and comments for redirection rules;
  • Added support for new macros for redirection rules.

Version 1.6.2:

  • Replaced TYPE=MyISAM with ENGINE=MyISAM;
  • Fixed issue with $basepath related to "/" encoded with %2F;
  • Fixed issue with creation of exclude referers list;
  • Hidden warning messages on preg_match macro (@preg_match) (only for Enterprise);
  • Hidden notice message "Notice: Undefined offset: 0:" on array_key_exists (only for Enterprise);
  • Replaced urlencode(<string>) with urlencode(utf8_encode(<string>)) (only for Enterprise);
  • Replaced urldecode(<string>) with utf8_decode(urldecode(<string>)) (only for Enterprise).

Version 1.6.0:

  • Completely rewritten for the new version of Joomla! 1.6 and 1.7;
  • The redirection rules can work on the entire URL, including protocol and domain;
  • It can be specified for each redirect rule whether or not to first decode the URL.

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.

As mentioned earlier the "From URL" field can contain a regular expression and can match the whole URL or just a part of it. The following table shows some regexp examples.

"From URL" fieldWhat does it mean
/section/*$ The dollar ($) means "end with". The star (*) means "match zero or more occurrences of previous character", that is the slash (/). So this rule means "address ends with /section or /section/".
^/section/9-article\.html$ The caret (^) means "start with". The dollar ($) means "end with". So the rule means "address starts and ends exactly with /section/9-article.html".
^/section/11-articles\.php\?id=12$ The caret (^) means "start with". The dollar ($) means "end with". Also, we need a "literal" question-mark (?) for inline arguments, so it must be escaped with a backslash (\?). So the rule means "address starts and ends exactly with /section/11-articles.php?id=12". Note that any special char needs to be escaped with a backslash to be literal, so we should escape also the dot (.) char. If not escaped, the dot will match with "any char".

The rules ordering is important for matching the source URL. For each URL request, all published rules are compared according to their ordering. Even if two or more rules match, ONLY THE FIRST ONE in the rule ordering will be used. This can be useful, as example, to distinguish a category from its articles. If we have two URLs as follow:

http://www.mysite.com/category/
http://www.mysite.com/category/article-1.html

Rules could be configured with the following "From URL" field:

Item OrderWrong OrderCorrect Order
5 /category/ /category/article-1.html
6 /category/article-1.html /category/

 

For http://www.mysite.com/category/article-1.html both rules match this URL, but only the first matching rule is applied so, if rules are configured in the wrong order, the redirect for page article-1.html will never be used.

Internal Redirect

This feature is available only in the Enterprise version of ReDJ. The 301 (Moved Permanently) or 307 (Temporary Redirect) redirects are client-side redirects. The user from his web browser requests a page (the source URL), and the web server responds with the address to which the page was moved (the destination URL). At this point, it is the client browser that makes a new request for the new address (i.e. is the client that performs the redirect).
With the "Internal Redirect" instead, is the web server that changes the page returned to web browser with the new destination. The result is a server-side redirect (i.e. the redirect happens "internally" to Joomla), and the user does not notice any URL change in the address bar. This is a great solution to create URL aliases and short URLs. Just as example, let's consider an existing URL like the following:

http://www.yoursite.com/index.php/component/reservation/event/4/forum

It is possible to create a rule with a redirection type 200 (Internal) that match to the following URL:

http://www.yoursite.com/training

The page content sent to client is exactly the same for both URLs, but the shortest URL is much friendly and better for SEF and SEO.

Dynamic Destinations (Macros and Placeholders)

Let's take a deeper look at "To URL" destination field. Since version 1.5 of ReDJ, a support for complex "macros" has been added, and this allows to create dynamic destinations. The version 1.7.1 introduces support for "placeholders", that adds a new dimension to build complex URL transformations.

When the URL request matches the "From URL" source field of a rule, if the destination field "To URL" contains one or more macros or placeholders, then ReDJ first calculates and replaces any placeholder and macro with its current value, builds the final "real destination" URL, and finally performs the redirect.

Macros allow, as example, to manipulate pieces of the current matching URL (e.g. a query variable), placeholders can define new variables using constant strings, macros and other (previous) placeholders, so both let you to create dynamic destinations as complex transformations of the current source URL.

Here a practical example of dynamic destinations and macro substitution:

Source URL http://www.yoursite.com/old/index.php?task=view&id=123&ItemId=3
ReDJ "To URL" http://{siteurl}/new.html{querybuild ItemId=12}
Destination URL http://www.yoursite.com/new.html?task=view&id=123&ItemId=12

 

Placeholders allow you to define a set of values where each value is associated and identified by a name. A placeholder can be used in the definition of other placeholders or in the definition of meta info (practically they are based on the same principle of the variables in programming languages). Syntax for defining a placeholder is name=value where 'name' is the placeholder identifier (placeholder valid name, like variables in PHP convention, starts with a letter or underscore, followed by any number of letters, numbers, or underscores), while 'value' can be any string, and can also contains macros or placeholders defined before, and both will be replaced with their current value. The syntax to use a placeholder is ${name}, where 'name' is the name of the placeholder. Each rule has a text area field to define any number of placeholders, one for each row. For example, if you enter:

a=this
b=${a} is
c=${b} an
d=${c} example

Putting the placeholder ${d} in a meta field (e.g. title or description), this field will assume the value 'this is an example'. Here is a practical example of how to use the placeholders to get a complex result through the use of available macros in a sequence of definitions. Let's assume we need to create a rule for URL:

http://www.mysite.com/index.php?option=com_content&view=article&id=53&Itemid=280

We want to withdraw the article id (53), and perform a look-up on the database for getting the article alias (using-joomla), to be used for example in the page title. We can define the following placeholders:

id={preg_match 1}/option=com_content&view=article&id=([0-9]+)/i{/preg_match}
alias={tableselect #__content,alias,id}${id}{/tableselect}

After this, putting ${alias} in the title field, this will be replaced by 'using-joomla' in the page.

The first thing to do is to enable ReDJ plugin. To enable the plugin go to menu "Extensions" -> "Plug-in Manager", find a system type plugin named "System - ReDJ Community" or "System - ReDJ Enterprise" in the plugin list, and click on it to access to plugin settings. Set "Status" to “Enabled”, and set other parameters on the right side according to your needs. Look at "Plugin settings" paragraph for detailed information about each parameter. Click on "Save & Close" button and check that the plugin is now enabled.

ReDJ Enable Plugin

Remember that is the plugin that "does the work". The ReDJ component is just the administrative interface for managing redirection rules an other features, but is the plugin that checks site requests and performs redirection and other actions when needed. So, the very first thing to do is to enable the plugin. Note that if you need to disable ReDJ, just disable the plugin.

Another thing to check is the plugins order that can be very important, especially if there are some other plugins that mess with the source URL, redirection and aliases. In most cases it is better to set ReDJ as the first system plugin, so it will be the first to be executed and to check any page call. Now ReDJ is ready to work! You can now create your first redirection rule, and test the redirection through the web browser. Be careful that you could get a cached page. To avoid this just clear server-side cache from backend (menu "Maintenance" -> "Clean Cache"), and client-side cache from your web browser.

The ErrorDocument directive

Some non-existing URLs are managed directly by Apache that returns the 404 error page.

ReDJ Apache 404 Error

To manage these URLs with ReDJ and make redirection it is necessary to tell to Apache to pass 404 errors to Joomla (and ReDJ). To do this, it is enough to append this directive at the end of Joomla standard .htaccess file:

ErrorDocument 404 /