Redirect

Last modified by Vincent Massol on 2021/12/15 17:22

cogAutomatically send users to the page defined between the brackets
TypeSnippet
Category
Developed by

Guillaume Lerouge

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

Once the snippet is added to a page, if you come back to that page in "view" mode you will be automatically sent to the page defined between the brackets.

XWiki 13.3+, 12.10.7+ If the URL passed to sendRedirect() is absolute, you'll need to add that domain to the list of allowed domains. Relative URLs, such as those returned by $xwiki.getURL() are fine.

Examples

Basic Redirects

  • Send the user to an external website
$response.sendRedirect("http://www.w3.org")
  • Send the user to another page on the wiki
$response.sendRedirect($xwiki.getURL('Some.Document'))
  • Send the user to another page on the wiki, in edit mode
$response.sendRedirect($xwiki.getURL('Some.Document', 'edit'))
  • Send the user directly to the edit mode of the page viewed
$response.sendRedirect($doc.getURL('edit'))

Advanced Redirects

  • Show the same page to the user but without applying the skin
$response.sendRedirect($doc.getURL('view', 'xpage=plain'))
  • Show the same page in wiki markup language but without applying the skin
$response.sendRedirect($doc.getURL('view', 'xpage=wml'))
  • Send to the same page but using a xml representation and without applying the skin
$response.sendRedirect($doc.getURL('view', 'xpage=xml'))
  • Send to a page to get a RSS Feed (need further explanation)
$response.sendRedirect($xwiki.getURL('Some.Document', 'view', 'xpage=rdf'))

XWiki 2.0 Syntax

Don't forget to embrace the snippet between Velocity tags when you work in XWiki 2.0 syntax.

{{velocity}}
$response.sendRedirect($xwiki.getURL('Main.Home'))
{{/velocity}}

Removing Redirects Again

Removing the redirect again, once added, can prove to be difficult if your default editor is the WYSIWYG CKeditor. In this case, the macro will even be executed in edit mode, redirecting you do to the target page before you have a chance to remove or alter the redirect.

So if your default editor is the WYSIWYG editor, and you want to edit a redirect on the following page:

https://xwiki.example.org/xwiki/bin/view/Main/

You manually have to change the URL as follows:

https://xwiki.example.org/xwiki/bin/edit/Main/?editor=wiki

This will cause the wiki text editor to open with the page's source code and the redirect can be edited or removed without any problems, even if your default editor is the WYSIWYG / CK editor.

Tags:
     

Get Connected