DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:redirect

Redirect Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" unknown
  • 2016-06-26 "Elenor Of Tsort" unknown
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

plugin Redirects page accesses to other pages or external sites using a central configuration file.

Last updated on
2017-11-05
Provides
Admin, Action
Repository
Source

Tagged with redirect

Download and Installation

Download and install the plugin using the Plugin Manager using the download link given above. Refer to Plugins on how to install plugins manually.

Changes

Configuration/Usage

The plugin stores a list of page/redirect pairs in a config file called redirect.conf in the plugin directory. This file needs to be writable by the webserver to edit it from the administration menu, section Other Plugins like the update plugin.

In order to implement the redirections manually, just place on the redirect.conf file lists of the old pages, followed by the new ones:

old_namespace:my_page new_namespace:my_page

On this example, when the users try to access old_namespace:my_page it will be redirected to new_namespace:my_page

Access to the configuration is granted for Managers and Superusers.

You may tell the plugin to show an info message to users when they were redirected. This can be done in the Config Manager.

Comments

301 redirects

If we change the following line in inc/common.php

header('Location: '.$url);

to

header('Location: '.$url,TRUE,301);

then instead of a 302 response - the default when no $http_response_code parameter is specified in header() - we get a 301 which is supposed to be better for SEO reasons.

Is such a change, or for that matter a modification of send_redirect() so that one can optionaly specify an $http_response_code other than 302, a good idea?

Wow! It handles redirects to external URLs too!

Thanks!
But I see no way to update redirect.conf from the Config manager…
Manual editing is ok. — jnojno

2011/07/08 13:27

3 years later (Ponder Stibbons release) there is a menu entry on the “Admin” page to configure the plugin. It contains the text of $lang['name']. It's not in the “redirect” part of the config manager… — Werner FlammeWerner Flamme
werner.flamme

2014-06-02 15:25 CEST

Wildcard redirection

A simple modification will add an ability to redirect whole namespaces (and even more) using simple wildcard syntax in config file:

myteam:*        contacts:mycompany:mydepartment:myteam:$1
client:*        contacts:clients:clientname:$1
server:*        it:system_dpt:resources:servers:$1

The fix:

action.php.diff
37a38,53
>
>         $newID = "";
>
>         foreach ( $redirects as $mask=>$target )
>         {
>               $regex_mask = '/^'.preg_replace( '/\*/', '(.*)', $mask ).'$/';
>
>               if ( preg_match( $regex_mask, $ID ) )
>               {
>                       $newID = preg_replace( $regex_mask, $target, $ID );
>                       break;
>               }
>         }
>
>         $redirects[$ID] = $newID;
>

Note that you'll need to symlink the directories in data/pages if you want internal links to show correct page status (available/missing).
— Michał Sacharewicz 2012/03/15 11:04

Please could someone tell me exactly, where (wich lines) i have to paste that code in or what i have to replace. Don´t understand the '37a38,53' Information. This function would be very useful (for me) for extracting parts of an older wiki to it´s own domain.

Thx. - Tobias 2013/02/21 11:04

Paste it after 37 string $redirects = confToHash(dirname(FILE).'/redirect.conf'); 37a38,53 mean “after 37 string, in new numbered 38-53 strings

This almost does what I need it to. I'm organizing my novel notes in dokuwiki and have it broken out into namespaces. I want to be able to quickly add [[character_name]] and have it properly link to characters:protagonists:character_name. But, if I link to the character from places:town, it creates the link to places:character_name, which is obviously not where the page is. If I set up the redirect with *character_name redirecting to characters:protagonists:character_name, it does indeed redirect in every applicable instance. Unfortunately, it creates an infinite loop because the ultimate destination also contains character_name. Is there a way to modify this so that it will exclude the destination page? My PHP isn't really up to snuff. Or if there's another plugin that will have the same effect. I just don't want to create individual redirect pages for every other page in every namespace. But I really just want to be able to type the name and throw a few brackets around it without have to type in the whole name with namespaces. — Matt 2014/8/27 05:56

Virtual Hostname Redirects

I needed something to redirect based on virtual hostname and path matches so I made a modification to let me do that with this plugin. Here are the changes I made in the action.php file.

 function handle_start(&$event, $param){
        global $ID;
        global $ACT;

        if($ACT != 'show') return;

        $redirects = confToHash(dirname(__FILE__).'/redirect.conf');
		$landing = $redirects[$ID];
		if( empty($landing) ) { $landing = $redirects[ $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']]; }
        if($landing){
            if(preg_match('/^https?:\/\//',$landing)){
                send_redirect($landing);
            }else{
                if($this->getConf('showmsg')){
                    msg(sprintf($this->getLang('redirected'),hsc($ID)));
                }
                $link = explode('#', $landing, 2);
                send_redirect(wl($link[0] ,'',true) . '#' . rawurlencode($link[1]));
            }
            exit;
        }
    }

If I add a line in the redirect.conf that says

workorders.mysite.com/ admin:workorders:start

anyone who comes in with that dns name at the root of my site will get redirected to the admin:workorders:start page.
— Matthew Mills 2013/07/05

Redirection based on group of logged in user

Is it possible to tweak this plugin to make it redirect a page to another page based on the group of the logged in user? In other words, I would like the target page to change depending on the group the user belongs to.

Thanks in advance. – Francesco 2013/09/12

Redirection to anchors

Hi there! Redirects like page another_page#anchor work just like page another_page I would like you to correct this behaviour.

Bug in Detritus

In the latest version of DokuWiki, redirects always add a hash at the end of the URL. This didn't happen with the previous version. — ziothzioth

2015-08-14 03:45

Please report bugs here: https://github.com/splitbrain/dokuwiki-plugin-redirect/issues

plugin/redirect.txt · Last modified: 2017-11-05 23:51 by andi