=== src/main/java/com/xpn/xwiki/XWiki.java
==================================================================
--- src/main/java/com/xpn/xwiki/XWiki.java	(revision 1397)
+++ src/main/java/com/xpn/xwiki/XWiki.java	(local)
@@ -431,6 +431,7 @@
                     getSkinClass(context);
                     getGlobalRightsClass(context);
                     getTagClass(context);
+                    getRedirectRuleClass(context);
                     getPluginManager().virtualInit(context);
                 }
 
@@ -812,6 +813,7 @@
             getCommentsClass(context);
             getSkinClass(context);
             getGlobalRightsClass(context);
+            getRedirectRuleClass(context);
             getStatsService(context);
         }
 
@@ -6201,4 +6203,30 @@
             context.getMessageTool().get("core.comment.rollback", params), context);
         return rolledbackDoc;
     }
+
+    public BaseClass getRedirectRuleClass(XWikiContext context) throws XWikiException
+    {
+        XWikiDocument doc;
+        boolean needsUpdate = false;
+
+        doc = getDocument(XWikiConstant.REDIRECT_RULE_CLASS, context);
+
+        BaseClass bclass = doc.getxWikiClass();
+        if (context.get("initdone") != null)
+            return bclass;
+
+        bclass.setName(XWikiConstant.REDIRECT_RULE_CLASS);
+
+        needsUpdate |= bclass.addTextField(XWikiConstant.REDIRECT_RULE_CLASS_PROP_PATTERN, "Pattern", 30);
+        needsUpdate |= bclass.addTextField(XWikiConstant.REDIRECT_RULE_CLASS_PROP_DESTINATION, "Destination", 30);
+        String content = doc.getContent();
+        if ((content == null) || (content.equals(""))) {
+            needsUpdate = true;
+            doc.setContent("1 XWiki RedirectRuleClass");
+        }
+
+        if (needsUpdate)
+            saveDocument(doc, context);
+        return bclass;
+    }
 }
=== src/main/java/com/xpn/xwiki/XWikiConstant.java
==================================================================
--- src/main/java/com/xpn/xwiki/XWikiConstant.java	(revision 1397)
+++ src/main/java/com/xpn/xwiki/XWikiConstant.java	(local)
@@ -3,4 +3,7 @@
 public class XWikiConstant {
     public static final String TAG_CLASS = "XWiki.TagClass";
     public static final String TAG_CLASS_PROP_TAGS = "tags";
+    public static final String REDIRECT_RULE_CLASS = "XWiki.XWikiRedirectRule";
+    public static final String REDIRECT_RULE_CLASS_PROP_PATTERN = "pattern";
+    public static final String REDIRECT_RULE_CLASS_PROP_DESTINATION = "destination";
 }
=== src/main/java/com/xpn/xwiki/web/Utils.java
==================================================================
--- src/main/java/com/xpn/xwiki/web/Utils.java	(revision 1397)
+++ src/main/java/com/xpn/xwiki/web/Utils.java	(local)
@@ -43,7 +43,12 @@
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.util.*;
+import java.util.HashMap;
 
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.XWikiConstant;
+import com.xpn.xwiki.objects.BaseObject;
+
 public class Utils
 {
     public static void parseTemplate(String template, XWikiContext context) throws XWikiException
@@ -523,4 +528,38 @@
         return component;
     }
 
+    /**
+     * Get redirection URL if base URL matches patterns in XWikiRedirectRule objects attached to
+     * the XWiki.XWikiPreferences page.
+     *
+     * @param context
+     * @param url Base url
+     * @return Redirection url, or null if no pattern matched
+     * @throws XWikiException
+     */
+    public static String getRedirection(String url, XWikiContext context) throws XWikiException
+    {
+        String database = context.getDatabase();
+        try {
+            context.setDatabase(context.getMainXWiki());
+            XWikiDocument preferences = context.getWiki().getDocument("XWiki.XWikiPreferences", context);
+            Vector redirects = preferences.getObjects(XWikiConstant.REDIRECT_RULE_CLASS);
+            if (redirects == null)
+                return null;
+            Iterator it = redirects.iterator();
+            while (it.hasNext()) {
+                BaseObject redir = (BaseObject)it.next();
+                String p = redir.getStringValue(XWikiConstant.REDIRECT_RULE_CLASS_PROP_PATTERN);
+                if (url.matches(p)) {
+                    String dest = redir.getStringValue(XWikiConstant.REDIRECT_RULE_CLASS_PROP_DESTINATION);
+                    return url.replaceAll(p, dest);
+                }
+            }
+        }
+        finally {
+            context.setDatabase(database);
+        }
+        return null;
+    }
+
 }
=== src/main/java/com/xpn/xwiki/web/XWikiAction.java
==================================================================
--- src/main/java/com/xpn/xwiki/web/XWikiAction.java	(revision 1397)
+++ src/main/java/com/xpn/xwiki/web/XWikiAction.java	(local)
@@ -22,7 +22,7 @@
 package com.xpn.xwiki.web;
 
 import java.io.IOException;
-
+import java.net.URL;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -114,15 +114,26 @@
                 Utils.prepareContext(mapping.getName(), request, response,
                     new XWikiServletContext(servlet.getServletContext()));
 
+            URL url = context.getURL();
+
             // Add the form to the context
             context.setForm((XWikiForm) form);
             XWiki xwiki = null;
             try {
                 xwiki = XWiki.getXWiki(context);
+                // Check user-defined redirections
+                String redirection = Utils.getRedirection(url.toString(), context);
+                if (redirection != null) {
+                    response.sendRedirect(redirection);
+                    return null;
+                }
             } catch (XWikiException e) {
                 if (e.getCode() == XWikiException.ERROR_XWIKI_DOES_NOT_EXIST) {
-                    // redirect
-                    String redirect = context.getWiki().Param("xwiki.virtual.redirect");
+                    // Check user-defined redirections first
+                    String redirect = Utils.getRedirection(url.toString(), context);
+                    // redirect to the "No wiki page" if no user-specified redirection
+                    if (redirect == null)
+                        redirect = context.getWiki().Param("xwiki.virtual.redirect");
                     response.sendRedirect(redirect);
                     return null;
                 } else {
