How to redirect Confluence users to a new URL

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Purpose

When content is moved, the Confluence administrator may need to redirect users from an old page (URL) to a new one.

For example, when pages are merged into a new one, you may need to keep the old page and redirect readers to the latest version.

Also, when Spaces are moved from a legacy instance to a new one, users might still try to access content through the legacy instance and they should be automatically redirected to the new one.

This document goes through possible places where a Confluence administrator may configure redirect rules so that users will still access the latest content (new page or new instance).

This document serves as just a list of suggestions where redirect rules can be configured and should not be considered as a complete guide.

Each option highlighted below can be adjusted to more complex rules and must be evaluated by the Confluence administrator.


Solution

Redirect on the Page Level

This example takes into consideration a single Page when users access it through the prettified URL, which is usually the most common use case.

Other use cases associated to the same page (such as viewing page attachments) are not considered.


Let's say the contents of a specific Page were moved to a new one within the same instance.
In this example, the content was merged into a new page, so the current one was not moved.
The old page was kept for historical reasons and to give context to users still accessing it.

So now you need to redirect readers from a Source to a Target page so they can access the most recent content.

In this case you may use the HTML Macro to include a page banner with a meaningful message and use the Meta refresh tag to automatically redirect the browser to the Target URL.


Below is the process to accomplish the above:

  1. Edit the Source Page and add an HTML Macro on the top of the page.
  2. Add the following as contents of the HTML Macro, changing TARGET_URL_HERE to the actual Target URL.

    <div style="background-color: yellow; border: 2px solid red; margin: 4px; padding: 2px; font-weight: bold; text-align: center;">
    This page was moved to <a href="TARGET_URL_HERE">TARGET_URL_HERE</a>
    <br>
    Click in the link above if you are not automatically redirected in 10 seconds.
    </br>
    </div>
    <meta http-equiv="refresh" content="10; URL='TARGET_URL_HERE'" />
  3. Publish the new version.
    1. Note the added banner and wait for 10 seconds to be redirected to the target URL. 


Source page on the edit mode with an example of the suggested
HTML macro and content.


Source page on the display mode with the example banner.


Redirect on the Space Level

A similar redirect strategy as the above example can be applied to all pages within the same Space by making changes in a single location.

This use case might be a good choice when a Space was migrated from a legacy to a new Confluence instance.


  1. On the legacy instance, access the target Space and go to Space Tools > Look and Feel > Layout.
  2. In Content Layouts, search for Page Layouts and click either on Edit or Create custom.
  3. In the Decorator Editor, search for the block of instructions setting the custom header.

    #set($customHeader = $helper.getCustomHeader($spaceKey))
    #if ($mode == "view" && $customHeader != "")
        <content tag="custom-content-header">
            <div id="custom-content-header">
                $customHeader
            </div>
        </content>
    #end
  4.  Modify it according to the example below, making sure to change TARGET_CONFLUENCE_BASE_URL_HERE with an actual value.

    #set($customHeader = $helper.getCustomHeader($spaceKey))
    #if ($mode == "view" && $customHeader != "")
        <content tag="custom-content-header">
            <div id="custom-content-header">
                $customHeader
    
    
                <!-- Redirect rule to all pages within the Space -- starts here -->
                <div style="background-color: yellow; border: 2px solid red; margin: 4px; padding: 2px; font-weight: bold; text-align: center;">
                This page was moved to <a href="TARGET_CONFLUENCE_BASE_URL_HERE$page.urlPath">TARGET_CONFLUENCE_BASE_URL_HERE$page.urlPath</a>
                <br>
                Click in the link above if you are not automatically redirected in 10 seconds.
                <meta http-equiv="refresh" content="10; URL='TARGET_CONFLUENCE_BASE_URL_HERE$page.urlPath'" />
                </div>
                <br>
                <br>
    			<!-- Redirect rule to all pages within the Space -- ends here -->
    
    
            </div>
        </content>
    #end
  5. Click on Save to publish the modifications.
  6. Still on the Space Tools, go to Look and Feel > Sidebar, header and footer.
  7. If you don't have anything configured in the Header Section, add the following content and save it – having any content here is necessary to activate the modifications made in the Layout Section.

    {html}
    <br>
    <br>
    {html}
  8. Access a sample page and notice the banner on the top of it.
    1. You should be redirected to the new instance within 10 seconds.


Example of modified Layout


Example of modifications to the Header


Example of redirect banner


Redirect on the Proxy Level

While the previous options require you to keep legacy content, this option allows you to completely remove them if a Reverse Proxy is configured in front of Confluence.

In that case, you may configure a rewrite rule on the proxy to send users' requests to the wanted content depending on what users are trying to access.

The configuration below is an example on NGINX that allows full access to an instance named confluence6101.thmas.com/c6101. When users try to view pages within the TS Space, they are redirected by the proxy to another instance.

Sample NGINX configuration
server {
    listen confluence6101.thmas.com:80;
    server_name confluence6101.thmas.com;

    location /c6101 {
        client_max_body_size 100m;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:26101/c6101;
    }

    location /synchrony {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:26101/synchrony;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    rewrite ^/c6101/display/TS/(.*)$ http://confluence6136.thmas.com/c6136/display/TS/$1 permanent;

}


Further Reading

CONFSERVER-58800 - Getting issue details... STATUS

Redirection for Confluence App

NGINX rewrite rules configuration tips

CSS-tricks - How to Redirect a Web Page


DescriptionRewrite rules to redirect access to different content
ProductConfluence



Last modified on Dec 2, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.