XWiki Short URLs

This page describes, how to shorten ../xwiki/bin/view/.. part from URL, using Apache Proxy module with Tomcat application server.

Installation

  1. Install Apache modules:

    sudo a2enmod proxy proxy_http proxy_html rewrite

Main space is shown as other spaces

In this case all XWiki documents are shown in form: http://host/Space/Page
  1. Add following lines at the start of the file /etc/apache2/sites-available/default (and /etc/apache2/sites-available/ssl, if it exists):

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/

    RewriteEngine On

    ## Proxy
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>

    #######################
    ## XWiki short URLs  ##
    #######################

    # Note that in this section all URLs must be started with /

    ## In this case Main space is shown as other spaces
    RewriteRule ^/xwiki/bin/view/(.*)$ /$1 [R=301,NE]
    # Drop ../WebHome
    RewriteRule ^/WebHome$ / [R=301,L]

    ## Proxy rules ##
    # to view other xwiki pages
    RewriteRule ^/xwiki/(.*)$ http://localhost:8080/xwiki/$1 [P,L]
    ## to view content pages without /xwiki/bin/view/...
    RewriteRule ^/.+$ - [C]
    RewriteRule !^/xwiki/.*$ - [C]
    RewriteRule ^/(.+)$ http://localhost:8080/xwiki/bin/view/$1 [P,L]

    ## debug
    #RewriteLog "/var/log/apache2/rewrite.log"
    #RewriteLogLevel 9

    ## Rewrite hyperlinks in HTML
    #ProxyHTMLDoctype HTML
    #SetOutputFilter proxy-html
    ProxyHTMLURLMap /(.*)/WebHome     /$1/   Rnl
    ProxyHTMLURLMap /xwiki/bin/view/ /       l

    ## cokies
    ProxyPassReverseCookiePath /xwiki /

    ## debug
    #ProxyHTMLLogVerbose On
    #LogLevel Debug

Main space is hidden

In this case documents in Main space are shown in form: http://host/Page, but all other in form: http://host/Space/Page.
  1. Change rules from previous sample to following:

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/

    RewriteEngine On

    ## Proxy
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>


    #######################
    ## Xwiki short URLs  ##
    #######################
    # Avoid !^/xwiki/… rule pattern, as it breaks Xwiki included URLs (/xwiki/bin/attach|save|ssx|preview|etc)
    # Don't redirect ^/xwiki/bin/preview/.. as it breaks saving

    # for pages in Main space
    RewriteRule ^/xwiki/bin/view/Main/(.*)$ /$1 [R=301,NE]
    # for pages in other spaces
    RewriteRule ^/xwiki/bin/view/(.*)$ /$1 [R=301,NE]
    # Drop ../WebHome for view
    RewriteRule ^/([A-Za-z0-9_]+)/WebHome$ /$1/ [R=301,L]
    RewriteRule ^/WebHome$ / [R=301,L]
    #Drop Main
    RewriteRule ^/Main/.*$  /$1 [R=301,NE,L]

    ## debug
    #RewriteLog "/var/log/apache2/rewrite.log"
    #RewriteLogLevel 9

    ## Rewrite hyperlinks in HTML
    #ProxyHTMLDoctype HTML
    #SetOutputFilter proxy-html
    ProxyHTMLURLMap /(.*)/WebHome     /$1/   Rnl
    ProxyHTMLURLMap /xwiki/bin/view/ /       l

    ## cokies
    ProxyPassReverseCookiePath /xwiki /

    ## debug
    #ProxyHTMLLogVerbose On
    #LogLevel Debug
  2. Reload Apache:

    /etc/init.d/apache2 reload

Problem solution

Body element attributes are lost, during link rewriting

Decrease continuous amount of spaces in produced HTML head. On Ubuntu 12.04 it was found, that if amount of spaces was more than 1000, mod_proxy_html module wrongly assumed that head part is finished, arbitrary closed head and opened body without attributes (and then ignored original one).

To fix that, in file /etc/apache2/mods-available/proxy_html.conf add line:

ProxyHTMLBufSize 16384

Wrongly coded non-latin characters

Enable xml2enc apache module and add following directive in configuration file:

SetOutputFilter xml2enc;proxy-html

Main content is lost when document is edited

Comment out/remove JavaScrip content for /usr/lib/xwiki/skins/flamingo/shortcuts.vm file:

###########################################
##        ADD KEYBOARD SHORTCUTS
###########################################
###if ($keyboardShortcutsEnabled)
##  <script type="text/javascript">
##  //<![CDATA[
##    shortcut.add("$services.localization.render('core.shortcuts.view.code')", function() {
##      location.href = $('tmViewSource').href;
##    }, {'type': 'keypress', 'propagate': false, 'disable_in_input': true });
##  //]]>
##  </script>
###end

Redirected links have double-escaped URIs

This was noted for the latest XWiki 6.1 version

Rewrite redirect rules wit NE (noescape) flag (already done in example code).

Alternatives

 

Izveidojis Valdis Vītoliņš 2013-11-09 15:24
Pēdējais mainījis Valdis Vītoliņš 2017-08-04 12:18
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License