01226: Allow Redirects even if target page does not exist

Summary: Allow Redirects even if target page does not exist
Created: 2010-09-26 12:06
Status: Discussion
Category: Feature
From: RandyB
Priority: 5
Version: 2.2.18

Description: The redirect markup is ignored when the target page does not exist.

Examples of why you might want to redirect to a non-existing page:

  1. You can define your category group to be "Categorized" and its group header could redirect to the "Category" group, so you can differentiate between links to a category (pages that link to Category.MyCategory) and actual categorizations of a page (!MyCategory).
  2. You can have new pages created in a different group by making the old group's header redirect to DifferentGroup.{$Name}.

There is a practical reason for this - if a target doesn't exist, the author most likely made a mistake/typo and should re-edit the page instead of being redirected away.

For your specific need, a workaround can be used from PHP. In a file local/RCategory.php (for example), you can have the following:
list ($g, $p) = explode (".", $pagename);
Thus, any link to, say RCategory.Test333?, will automatically redirect to [[Category.Test333]].

If many people need the "Enable redirects to non-existing pages" feature, we may be able to add an extension, like with the redirect quiet=1 parameter. What markup do you think would be most appropriate? --Petko November 09, 2010, at 03:53 AM

Your workaround may be enough for me - I'll try it. Here are some ideas for enhanced markup (if you go there): allow a fallback pagename that will be used even if it doesn't exist. For example: (:redirect AnotherPage:) would work as it does now, showing an error message if AnotherPage doesn't exist. (:redirect Category.{$Name} Category.{$Name}:) would go to the page even if it doesn't exist, with no error message. (:redirect AnotherPage {$FullName}:) would go to AnotherPage if it exists, otherwise would stay on the current page with no error message. An alternative would be to have a parameter "always=1" to force the redirection if the page doesn't exist, and "quiet=1" to suppress the error message. Then you could have the error message and the page the user ends up on be independent and under the author's control. - RandyB November 09, 2010, at 09:50 AM