How to replace all hard coded links after a base URL change

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

When changing the Base URL, either due to a URL change or from an export/import (e.g. Cloud to Server or Server to Server) absolute links to the old Base URL need to be changed.

Example Server to Server

Old Base URL http://mycompany.com/confluence
New Base URL http://confluence.mycompany.com/

Example Cloud to Server (this requires extra steps)

Old Base URL http://mycompany.atlassian.net/wiki
New Base URL http://confluence.mycompany.com/

Please note that Cloud to Server Base URL change requires extra steps due to these known issues

Resolution

Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

Option 1: Export/Import Option using Find and Replace

This option outlines how to export your Confluence data and perform a find/replace leveraging the sed script notated below to update the link values. 

1. Choose an export method and generate the export file

Option A: Generate a site XML export file

(warning) The XML backup method can be a resource intensive operation that can cause performance issues depending on the size of your instance. If your Confluence instance is very large, we would recommend running this operation over a maintenance window in an abundance of caution.

Full site export

  1. Go to > General Configuration > Backup & Restore
  2. Check Back up attachments
  3. Click Back Up
  4. Find the xmlexport file (usually) in <confluence-home>/temp
  5. Extract the entities.xml file from the xmlexport file
  6. Shut down Confluence

Option B: Generate a database export file

Use a native database tool to export all the data. This requires Confluence to be shut down.

    • For MySQL use mysqldump

    • For PostgreSQL use pg_dump

2. Run the sed script against your export file to find and replace the old URL value with the new value

Run the following sed script on the export file you generated.

Basic Syntax Example
sed -r -e 's/oldvalue/newvalue/g' <export-file-name>

As an example, the following script would be ran for an instance where the old URL is http://mycompany.com/confluence and the new URL is http://confluence.mycompany.com. Note that the script contains escapes for the forward slash characters contained in the URL. This example references example site export file entities.xml.If you are running this against a database export, you would replace this file with your resulting export.sql file.

Example Script with URL Values
sed -r -e 's/mycompany.com\/confluence/confluence.mycompany.com/g' entities.xml
For Cloud exports only ...

Cloud exports will use the entities.xml file for the backup zip

  1. For CONFSERVER-54759 - Getting issue details... STATUS
    Replace all content URLs to Confluence Server format with this command (using the example URLs above)

    sed -r -e 's/mycompany\.atlassian\.net\/wiki\/spaces\/[A-Z0-9]+\/pages\/([0-9]+)\/[A-Za-z0-9+.]+/confluence.mycompany.com\/pages\/viewpage.action?pageId=\1/g' entities.xml
  2. For CONFSERVER-45919 - Getting issue details... STATUS
    Replace incorrect Base URL entry from N/A

    sed -r -e 's/<server\.base\.url>N\/A</server\.base\.url>/<server.base.url>http://confluence.mycompany.com</server.base.url>/g' entities.xml

3. Reimport the updated export file

Option A: Site XML Import

Using this option will require extra steps to re-load all the Add-ons from http://marketplace.atlassian.com/

  1. Re-zip up the xmlexport file, taking care to place the files in the same location as the original export.
  2. Go to > General Configuration > Backup & Restore
  3. Click Choose file and select the new xmlbackup xip file
  4. Click Upload and Restore
Option B: Database import

Use the database tools to re-import the data.

Option 2: WebDAV option

Use the WebDAV plugin and mount the WebDAV location locally, then run a script that uses sed to replace all of the Old Base URLs. This option creates a new page version for all pages that are changed (this includes any page versions that are crawled and edited).

Option 3: Confluence Source Editor option

You can use the Confluence Source Editor app to modify content on a page-by-page basis.

  1. Install the Confluence Source Editor app.
  2. Open the editor on an affected page.
  3. Click the <> button on the top right of the editor.
  4. Replace any occurrences of the old base URL with the new base URL.
  5. Save the page.

This technique has the benefit of being less risky than doing direct data manipulation and it's easier than manually linking the attachment through the editor interface. 


Last modified on Jun 18, 2019

Was this helpful?

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