You are here: System » RedirectPlugin

RedirectPlugin

11 Feb 2025 - 16:46 | Version 1 |

Create a redirect to another topic or website.

I typically use this to make easy-to-type shortforms/acronyms of topic names. For example:
  • Actual content appears under Main.LightweightDirectoryAccessProtocol
  • Main.LDAP contains just a redirect tag. Referencing Main.LDAP anywhere or entering it in the Jump box takes one directly to Main.LightweightDirectoryAccessProtocol

Syntax Rules

  • Redirect to a topic within the web: %REDIRECT{"SomeTopic"}%
  • Redirect to a topic in another web: %REDIRECT{"Someweb.SomeTopic"}%
  • Redirect to any URL: %REDIRECT{"http://wikipedia.org/"}%
  • Pass parameters:
    • Url parameters are passed on: http://mia.phsz.ch/Main/TopicThatContainsARedirect?q=LDAP"}%. The landing topic url will contain these parameters
    • Parameters can also be passed to the variable: %REDIRECT{"Someweb.SomeTopic?q=LDAP"}%
    • REDIRECT parameters override url parameters

Prevent redirecting

To view the topic that contains a REDIRECT, pass parameter noredirect=on to the url. For example:

http://mia.phsz.ch/Main/WebHome?noredirect=on

Wikipedia like "Redirected from..."

A redirect now appends the redirectedfrom parameter to the url which contains the Web.Topic that the user has been redirected from. This allows us to display Wikipedia like "Redirected from ..." text on the destination topic. You can use the %URLPARAM{redirectedfrom}% variable to access the parameter and create the "Redirected from..." text.

Below is an example you can put in your template:

%IF{ "$'URLPARAM{redirectedfrom}'" then="<span class='foswikiGrayText'>(Redirected from <a href='%SCRIPTURLPATH{view}%/%URLPARAM{redirectedfrom}%?noredirect=on'>%URLPARAM{redirectedfrom}%</a>)</span>"}%

Which will display the following on topics that have been redirected:

(Redirected from Web.Topic)

Don't check that the target topic exists

If you pass the dontcheck=1 parameter then Foswiki will let you redirect to a topic that doesn't exist. This is very useful as a way to wrap up data form creators for applications.

e.g. RoleCreator:

%REDIRECT{newtopic="%SCRIPTURLPATH{"edit"}%/%BASEWEB%/UnnamedRoleAUTOINC1?topicparent=RoleList;templatetopic=RoleTemplate;t=%SERVERTIME{"$day$hour$min$sec"}%" dontCheck="1"}%

Now, for instance in WebLeftBar you can just use:
   * [[RoleCreator][Create Role]]

Test topics

If installed:

Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. "Extensions Operation and Maintenance" Tab -> "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button. Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will not show up in the search results.

You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
cd /path/to/foswiki
perl tools/extension_installer <NameOfExtension> install

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See https://foswiki.org/Support/ManuallyInstallingExtensions for more help.

Dependencies

None

Change History

11 Feb 2025: (2.00) OO-rewrite; fixed order of query and anchor in redirect url
03 Jul 2015: (1.12) Call cgi param in scalar context. Foswiki:Main.GeorgeClark
04 Feb 2014: (1.11) don't redirect coming from an edit - Foswiki:Main.MichaelDaum
25 Jun 2010: (1.1) Fixed Foswiki:Tasks/Item1527 - Foswiki:Main.ItaloValcy
07 Mar 2010: Added facility to dontcheck destination topic exists - Foswiki:Main.MartinCleaver
09 Apr 2009: Ported to Foswiki as 1.0; Update documentation - Foswiki:Main.AndrewJones
24 Nov 2008: Ability to display Wikipedia like "Redirected from..." - Foswiki:Main.AndrewJones
22 Apr 2007: Arthur Clemens: url parameters are now passed on. Adapted from TWiki:Main.JohnRouillard.
21 Apr 2007: Arthur Clemens: fixed redirect to non-wiki word topics; added noredirect=on parameter; added support for TWiki:Codev.ShorterURLs.
10 Aug 2006: Ability to redirect to URL restored by TWiki:Main/ThomasWeigert. Also added support for URL parameters. Fixed a few bugs.
09 Jun 2006: Dakar port by TWiki:Main/MeredithLesley
20 Jun 2003: Initial version
Kontakt
Pädagogische Hochschule Schwyz
Zaystrasse 42
CH-6410 Goldau
T +41 41 859 05 90
info@phsz.ch Dies ist ein Wiki des Fachkerns Medien und Informatik der Pädagogischen Hochschule Schwyz. Für Fragen wenden Sie sich bitte an wikiadmin@phsz.ch
This page was cached on 22 Feb 2025 - 19:52.
This website is using cookies. More info. That's Fine