XWiki Short URLs
Must prepare before: XWiki uzstādīšana no ražotāja vietnes Apache tīmekļa serveris Tomcat tīmekļa lietotņu serveris |
- Installation
- Main space is shown as other spaces
- Main space is hidden
- Problem solution
- Alternatives
- Links
Installation
Install Apache modules:
sudo a2enmod proxy proxy_http proxy_html rewrite
Main space is shown as other spaces
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
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 DebugReload 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:
Wrongly coded non-latin characters
Enable xml2enc apache module:
a2enmod xml2encAdd following directive in /etc/apache2/apache2.conf configuration file:
SetOutputFilter INFLATE;xml2enc;proxy-html;DEFLATE
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
Rewrite redirect rules wit NE (noescape) flag (already done in example code).
Alternatives
Links
- http://platform.xwiki.org/xwiki/bin/view/Main/ShortURLs
- http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
- http://httpd.apache.org/docs/2.4/mod/mod_proxy.html
- http://httpd.apache.org/docs/2.4/mod/mod_proxy_html.html
- http://validator.w3.org/
Created by Valdis Vītoliņš on 2013-11-09 13:24
Last modified by Valdis Vītoliņš on 2022-09-16 00:11