Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use Confluence for hostname redirects

Nathan Veeder July 31, 2015

We are migrating our Confluence 5.7 site and would like existing bookmarks to remain functional while forcing the use of the new hostname set as the base url (e.g. https://confluence.foo.com will become https://confluence.bar.com).  We are not using Apache or other web front end and would like to handle rewriting requests using the old name with Tomcat/Confluence app itself.  SSL is terminated at a load balancer and Confluence is running on HTTP over TCP 8080.
To configure the application to rewrite requests similar to as we have done successfully with JIRA in the past, we've edited confluence/WEB-INF/urlrewrite.xml to add the following block at the top of the <urlrewrite> section:
    <rule>
    <condition name="host">confluence.foo.com</condition>
    <from>^(.*)$</from>
    <to type="permanent-redirect">https://confluence.bar.com$1?%{query-string}</to>
    </rule>

This rule does not change requests using the previous name (i.e. https://confluence.foo.com/... requests are still served instead of being redirected to https://confluence.bar.com/...).  
The tuckey urlrewrite filter seems bundled in Tomcat with Confluence as it is with JIRA. 

Has anyone used it successfully? 

Any suggestions how to troubleshoot or implement this rewrite configuration using Tomcat/Confluence?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Shane Arnold November 27, 2016

An old question but is something I have just finished tackling;

WARNING: May break navigation icons, other graphics, e.t.c Haven't figured that out yet.

web.xml

&lt;!-- this filter is used to rewrite through the /s/* filter to add caching headers. see: urlrewrite.xml --&gt;
    &lt;filter&gt;
        &lt;filter-name&gt;UrlRewriteFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;org.tuckey.web.filters.urlrewrite.UrlRewriteFilter&lt;/filter-class&gt;
                
                &lt;init-param&gt;
                &lt;param-name&gt;confReloadCheckInterval&lt;/param-name&gt;
                &lt;param-value&gt;60&lt;/param-value&gt;
                &lt;/init-param&gt;
                
    &lt;/filter&gt;
    
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;UrlRewriteFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
        &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
    &lt;/filter-mapping&gt;

urlrewrite.xml

&lt;rule&gt;
        &lt;name&gt;Primary Domain Name Check&lt;/name&gt;
        &lt;condition name="host" operator="notequal"&gt;good-confluence-url.int&lt;/condition&gt;
        &lt;from&gt;^(.*)&lt;/from&gt;
        &lt;to type="redirect"&gt;http://good-confluence-url.int:8080$1&lt;/to&gt;
    &lt;/rule&gt;
Mike
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 19, 2019

This is extremely helpful. Thank you

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 1, 2015

Confluence is a web-application, there's no real-world use for rewrites within it, and it's completely the wrong tool for the job (like trying to open the cat-food tin with a spoon)

You can do some primitive rewrites in Tomcat, but it's also really not what it is for, so it's clunky and not very flexible (opening the tin with a hacksaw - it's wrong, but it can do the job)

Seriously, use the right tool - stick apache/nginx/lighttpd or something in place and do it the easy way.  (Use a tin opener to open tins)

Nathan Veeder August 3, 2015

Confluence 5.7 is bundled with UrlRewriteFilter 4.0.4, a JAVA web filter made for rewriting URLs: http://www.tuckey.org/urlrewrite/

The code block above is valid in urlrewrite.xml to enforce the hostname rewrite, however we've found it fails because the url-patterns set in Confluence in confluence/WEB-INF/web.xml for UrlRewriteFilter are limited to only:

<url-pattern>/s/*</url-pattern>
<url-pattern>/images/icons/*</url-pattern>

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2015

It's not included for enabling what you're trying to do. As I said already, use the right tool for it!

Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 13, 2015

Agreed with Nic. The Tuckey URLRewriteFilter is specifically included for the use by the application. Any customization you make to it would have the potential to break your installation, make upgrades/migrations difficult, or as you noticed, may not work entirely. I'd second the recommendation to use your own webserver and consider Confluence's Tomcat part of the Confluence internal bits of the application, aka off limits for most changes.

TAGS
AUG Leaders

Atlassian Community Events