create new tag
, view all tags

Archive of RedirectPluginDev discussions

Managing Redirects

I've created a sample application to ManageRedirects. The redirects won't work because TWiki.org doesn't run the plugin but you can see how it would allow finding and updating redirect topics.

It shouldn't allow creating a topic if it already exists unless you use the edit links in the table but I think that the onlynewtopic url parameter to the save script is not being obeyed at the moment.

-- SamHasler - 03 Sep 2004


-- SteveMokris - 21 Jun 2003

Looks useful, thanks Steve!

-- MartinCleaver - 21 Jun 2003

Possible problems to tinker with:

  • self links (times out in some browsers, not sure of all though)
  • circular redirections (TopicA -> TopicB -> TopicC -> TopicA ...)

-- ChrisWright - 2003.06.21

Minor detail: Add your signature to the Plugins topic so that the author is shown in the PluginPackage index table.

-- PeterThoeny - 19 Jul 2003

Very nice plugin! I use this on an extranet setup to send users to assigned webs, by setting a variable HOMETOPIC in their user's topic. So they type in a short URL, this redirects them to twiki/view/ (using meta refresh), then they log in, and they will be sent to their respective HOMETOPIC.

-- ArthurClemens - 25 Feb 2004

Refactored from UserSpecifiedRedirect:

Any page with REDIRECT cannot be edited by standard means (because -view= to render edit will redirect) so you need to search for pages with REDIRECT, and then go directly to edit - maybe it deserves some special formatted search in AdminTools smile

-- PeterMasiar - 07 May 2004

I think the following solution would provide better and more visible functionality:

Could this be changed to behave like MediaWiki's redirect in the way it adds a link back to the original topic with a redirect=no parameter?

Also, see Wikipedia:Wikipedia:Redirect for all the uses this is put to.

-- SamHasler - 27 Aug 2004

A very useful plugin. Thanks much. I have a suggestion - it would be nice to be able to specify a duration after which the redirection takes place. The time lapse can be used to display a message (in the redirection topic) to the visitor if the redirection is to an external URL.

-- SriramAcharya - 31 Aug 2004

On AvoidRenameLosingHistory I propose a pair of handlers to manage renames that would avoid the need for dropping the dummy text file. I'd be interested in your comments.

-- MartinCleaver - 03 Oct 2004

The current regex used in the redirect does not allow for redirection to Web.WikiTopic#Anchors or Web.WikiTopic#Other_Anchors (as produced by %TOC% so I would like to suggest the following changes:

    if( !($ENV{SCRIPT_NAME} =~ /preview/) ) # make sure we don't redirect on preview!
        if( $_[0] =~ /%REDIRECT\{\"([A-Z]+[A-Za-z]+)\.([A-Za-z0-9.-]+#[A-Za-z0-9]+\w+)?\"\}%/ )
        if( $_[0] =~ /%REDIRECT\{\"([A-Za-z0-9.-]+)(#[A-Za-z0-9]+\w+)?\"\}%/ )
        if( $_[0] =~ /%REDIRECT\{\"(.+\:\/\/.+)\"\}%/ )
-- TravisBarker - 02 Apr 2005

Working Demo of the above change at ThetaBase

-- TravisBarker - 02 Apr 2005

I have also implemented a MediaWiki-like structure that SamHasler talked about above. (This is why I noticed the problem redirecting to anchors in the first place)

-- TravisBarker - 02 Apr 2005

CDot suggested we use $regex or $regexp to eliminate the problem my change brings with the cross web redirects

-- TravisBarker - 05 Apr 2005

Minor defect - the regexs disallow numerals in the web name, as well as underscores in the web or page name. I believe both are valid. O/w it's a very useful plugin!

-- KevinJarnot - 05 Apr 2005

WikiMedia has the useful url param redirect=no to allow direct topic access with no redirection.

-- ArthurClemens - 07 Nov 2005

When a topic with a REDIRECT is included in another topic, the redirect should actually be disabled.

-- ArthurClemens - 17 Nov 2005

I wanted to use redirects with query parameters, but the current code doesn't support this, so I whipped up this patch to pass the query string through to the redirected page.

--- TWiki/Plugins/RedirectPlugin.pm~    2003-06-20 21:53:40.000000000 -0400
+++ TWiki/Plugins/RedirectPlugin.pm     2006-03-01 21:58:29.916125955 -0500
@@ -67,15 +67,24 @@
     my $query=&TWiki::Func::getCgiQuery();
+    my $i, $qs="";
+    foreach  $i ($query->param) {
+       $qs .= "&" if $qs;
+       $qs.="$i=" . $query->param("$i");
+       &TWiki::Func::writeDebug( "- RedirectPlugin::commonTagsHandler name=$i, qs=$qs") if $debug;
+    }
     if( !($ENV{SCRIPT_NAME} =~ /preview/) ) # make sure we don't redirect on preview!
         if( $_[0] =~ /%REDIRECT\{\"([A-Z]+[A-Za-z]+)\.([A-Za-z0-9.-]+)\"\}%/ )
-            &TWiki::Func::redirectCgiQuery($query,&TWiki::Func::getViewUrl($1,$2));
+            &TWiki::Func::redirectCgiQuery($query,&TWiki::Func::getViewUrl($1,$2) . "?$qs");
         if( $_[0] =~ /%REDIRECT\{\"([A-Za-z0-9.-]+)\"\}%/ )
-            &TWiki::Func::redirectCgiQuery($query,&TWiki::Func::getViewUrl($_[2],$1));
+            &TWiki::Func::redirectCgiQuery($query,&TWiki::Func::getViewUrl($_[2],$1) . "?$qs");
         if( $_[0] =~ /%REDIRECT\{\"(.+\:\/\/.+)\"\}%/ )

-- JohnRouillard - 02 Mar 2006

I have added a feature to generate redirects to TopicTree.

  • NewTerms
    • redirect-to-above-from: NewTerm1
    • redirect-to-above-from: NewTerm2
See GeneralizingTopicTrees

-- AndyGlew - 17 May 2006

This plugin has existed since 2003. Now Meredith has updated it for TWiki4 (which is good) but!!!

  • The version of the just uploaded version presents itself as the initial version. It is not! Please restore the history.
  • The new version says that it is tested on TWiki4 only. What about people still on Cairo? Can they use the new version? If not - please make sure that the Cairo compatible version is still available.

-- KennethLavrsen - 10 Jun 2006

The previous version was marked as being tested only on 01 Dec 2001. It also allowed redirections to external URLs, which presumably is undesirable given the current spam issues.

If someone would like to attach the previous version for pre-Dakar as well, I certainly don't mind, although be sure to note that it allows easy abuse by spammers.

-- MeredithLesly - 11 Jun 2006

I restored the original zip file from the Trash web, and re-attacked the latest version to it. I also fixed the author info and restored the initial version info in the Plugin info table.

And yes, it would be helpful to some community members if this Plugin still works on Cairo.

-- PeterThoeny - 11 Jun 2006

The spam issue does not apply for behind firewall use. The external redirect can be made conditionally with a Plugin setting.

-- PeterThoeny - 11 Jun 2006

I should probably have just made a new plugin with a different name, which is what I generally do with plugins that don't work with Dakar or need substantial cleaning up. The only reason I didn't was that it was marked as tested on 2001, which seemed to indicate that it was extremely old and may as well be replaced.

-- MeredithLesly - 11 Jun 2006

No, it is better to maintain an existing Plugin.

-- PeterThoeny - 12 Jun 2006

If the current version works in Cairo, then it should be marked as tested on Cairo as well. I don't have the ability to test against Cairo. Otherwise, I suppose the previous version should be attached as well and marked as Cairo.

And, actually, I take back the spam comment, as the previous version didn't redirect to anything but other topics either. (I should say that I think that's true, although I have no idea what the last regex was supposed to do.)

-- MeredithLesly - 12 Jun 2006

It definitely does not work anylonger in Cairo because of functions such as TWiki::Func::registerTagHandler, TWiki::Func::getContext, and also not because of the 1.1 format of the topic text. So, those who'd like to use it in a previous TWiki need to hunt down the right zip file.

BTW, the latest Plugin attached today does not contain the updated Plugin topic in SVN.

-- PeterThoeny - 12 Jun 2006

There needs to be a way to update those automatically. /me pokes CDot.

-- MeredithLesly - 12 Jun 2006

Syntax says:

  • Redirect to a topic within the web: %REDIRECT{"WikiWord"}%
Yet code says:
  • TWiki::Func::registerTagHandler('REDIRECTTO', \&REDIRECTTO);

-- MartinCleaver - 19 Jul 2006

Despite the discussions above calling attention to the lack of an older, Cairo-compatible version of the plugin, I find that this condition still exists. RedirectPlugin.zip-r3 and -r2 are both too new for Cairo judging by the value of $TWiki::Plugins::VERSION, RedirectPlugin.zip-r1 and RedirectPlugin.tgz-r1 are corrupt archives.

Could someone please correct this and add a Cairo version of the plugin as a seperate attachment to the RedirectPlugin topic?

-- RobertMiller - 21 Jul 2006

I think that's an excellent idea, one that I've been advocating for a while. (separate plugins for Cairo and Dakar, that is). Currently BuildContrib doesn't support it (I think), and there is not standard way (or even "approved" way) to do this. (Some people think that it's too difficult for administrators to figure out which version of the plugin to use, thus this issue languishing in limbo.) Perhaps you could bring this issue up in Codev?

Also, if someone has a Cairo version, it would be great if it were attached to the plugin topic, clearly marked for Cairo. My bad for not having kept the tarball for Cairo.

And yes, the code should be changed to REDIRECT in both spots. I'm having a spot of trouble with BuildContrib atm quite apart from supporting separate versions.

-- MeredithLesly - 30 Jul 2006

Small, tiny issue. I noticed the documentation on the Plugin page says:


Which should be (note Text vs Test):


Also, I noticed this in the logs:

view: Use of uninitialized value in string eq at /usr/local/wiki-var/lib//TWiki/Plugins/RedirectPlugin.pm line 84

I know its not vital, but its annoying to wade through when going over the logs. Finally, when I installed this plugin on Dakar, I had to go into config and enable this plugin before it would work (otherwise I could see the plugin rendered as plain text). It would be nice if the instructions where updated, it seems like the plugin template should be updated as well (I don't know who does that though).

-- EricHanson - 08 Aug 2006

Updated the plugin to match the documentation (use REDIRECT ). Restored the ability to redirect to arbitrary URL. Support the passing of URL parameters to the redirected topic. Fixed a few bugs. Use strict. Do not generate above error message in log. Note that this version is only in the zip file...

-- ThomasWeigert - 13 Aug 2006

Can I put a META tag in a redirect? I tried

and it appears to resolve the meta tag properly, but not the redirect... I get "Cannot redirect to ParentTopic". Tried with and without quotes.

-- GregPendlebury - 09 Nov 2006

The problem is that the %META{"parent"}% generates a result of the form [[...][...]], which is not recognized by %REDIRECT{}%. If you read the documentation, you will find that the parent tag usually generates a cookie trail. Nevertheless, I agree that it is quite reasonable to expect that one gets a normal topic returned, at least in the simple form.

You could use SpreadSheetPlugin to remove the anchor brackets in the result and pass it to redirect then...

-- ThomasWeigert - 13 Nov 2006

Thanks for the help Thomas... maybe I did it the wrong way, but this works if anyone wants a shortcut:

%REDIRECT{%CALC{$REPLACE($REPLACE($REPLACE(%META{"parent"}%, 1, 2), -2, 2), 1, $FIND([, $REPLACE(%META{"parent"}%, 1, 2)))}%}%

-- GregPendlebury - 13 Nov 2006

This works everywhere:

%REDIRECT{%CALC{$REPLACE($REPLACE($REPLACE(%META{"parent" dontrecurse="on"}%, 1, 2), -2, 2), 1, $FIND([, $REPLACE(%META{"parent"}%, 1, 2)))}%}%

-- GregPendlebury - 06 Dec 2006

I installed the Plugin and it is enabled with configure.

$TWiki::cfg{Plugins}{RedirectPlugin}{Enabled} = 1;

I have a topic with a line




When I the browser goes to the page all I see is the actual REDIRCT text. With DEBUG=1 I receive an OK in the debig.txt file

The plugin does not who up in TWiki/InstalledPlugins

I downloaded the zip file today.

What could be wrong?

-- PeterJones - 31 Jan 2007

Do you have the plugin 'turned on' from your TWiki config page?

-- GregPendlebury - 04 Feb 2007

Curremt RedirectPlugin does not workwith ShorterURLs. The following patch work for us:

--- lib/TWiki/Plugins/RedirectPlugin.pm.orig    2006-08-13 05:38:56.000000000 +0400
+++ lib/TWiki/Plugins/RedirectPlugin.pm 2007-02-15 20:18:42.000000000 +0300
@@ -63,8 +63,8 @@
     my $urlparams = '';
     my $dest = $params->{'newtopic'} || $params->{_DEFAULT};

-    # Redirect only on view.
-    if ($context->{'view'} && $dest) {
+    # Do not Redirect on edit.
+    if (! $context->{'edit'} && $dest) {
         my $query = TWiki::Func::getCgiQuery();
         $dest = TWiki::Func::expandCommonVariables($dest, $topic, $web);

@@ -102,7 +102,7 @@
            $urlparams = $dest;
            $dest = '';
+       chomp $dest;
        unless ($dest) {
             TWiki::Func::redirectCgiQuery($query, TWiki::Func::getViewUrl($newWeb, $newTopic) . $anchor . $urlparams);

-- SergejZnamenskij - 17 Feb 2007

I just ran into the same problem as PeterJones and figured out that the problem was the documentation! The required syntax (which I gathered from the Sandbox example in the distribution) is %REDIRECTTO{"SomeTopic"}% - i.e. the tag is REDIRECTTO rather than REDIRECT as stated in the docs. I am going to update the plugin package.

I think the REDIRECT is better. If there's a coder that has interest, perhaps they could change the plugin to accept both.

-- LynnwoodBrown - 07 Mar 2007

The attached plugin zip was very old. Meredith and Thomas had fixed the plugin several times but none of them ever uploaded their changes. I have done this now and I did not change a single line of code. The updated version should again match the spec and use REDIRECT.

-- KennethLavrsen - 08 Mar 2007

For newer discussions see RedirectPluginDev

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2007-04-21 - PeterThoeny
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.