Broken link on page when copying the space
Asked by Dominik Gashi:

Hi there,

I have a space with multiple pages. In the pages I have links to other pages in the same space. I had to copy the whole space. Now all links of the pages in the copied space refers to the pages in the old space.

I want that the links would refer on the page in the copied space.

I have thousands of pages with links in that space and to change those manually it would take a lot of time. Is there maybe a workaround?

Thanks.


Answers:
author: Helmy Ibrahim _Adaptavist_
body: Hi [@Dominik Gashi](/t5/user/viewprofilepage/user-id/5247031)

I am with the ScriptRunner Support Team.

Following up on [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201)'s comment, we do have an example of a find-and-replace script that you can use with ScriptRunner to bulk update Confluence's page storage format.

Please find it here: <https://www.scriptrunnerhq.com/inspiration/blog/find-and-replace-text-across-several-confluence-pages>

From what I understand, the links in the target Space refer to the pages in the source Space. If that is the case, you would need to update the parameter value of *ri:space-key* from the source-space key, to the target-space key.

For reference, here is what the Confluence Link storage looks like:

```
<ac:link>
    <
        ri:page 
        ri:space-key="SPACEKEY" 
        ri:content-title="PAGE TITLE HERE" 
    />
</ac:link>
```

Let me know if you have any further questions!

Kind Regards,  
Helmy

comments: author: Dominik Gashi
body: Hi [@Helmy Ibrahim _Adaptavist_](/t5/user/viewprofilepage/user-id/4130170)

Thank you for following up Andrii's comment and for the detailed explanation. I could solve it with the ScriptRunner.


author: Andrii Maliuta
body: Hello [@Dominik Gashi](/t5/user/viewprofilepage/user-id/5247031) ,

Looks like you set those links as WEB links and not as Confluence Smart links

* Cloud: <https://support.atlassian.com/confluence-cloud/docs/insert-links-and-anchors/>
* Server/DC: <https://confluence.atlassian.com/conf85/links-1283359750.html>

so it is treated as just href HTML text and after you move or copy the page it will remain static.

If you set links to Confluence pages/blogs/attachments as SMART links, it will adjust when renaming/copying/moving as needed.

You can change the links format using scripts or custom apps.addons.

comments: author: Dominik Gashi
body: Hello [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201) ,

Thank you for your message and for your help! The links we are using are normal links that refer to a page on that space. When copying the whole space in refers still to the old page in the old space not in the copied page in the copied space.

I think smart links are only available in Cloud. We are on Confluence Server. You mentioned that it's possible to change the links with apps. Do you know by change an app that can do that?

Thanks.


author: Andrii Maliuta
body: [@Dominik Gashi](/t5/user/viewprofilepage/user-id/5247031)

the 2nd link I mentioned is for Server/Data Center (

* Server/DC: <https://confluence.atlassian.com/conf85/links-1283359750.html>

)

Please check the **Storage Format** of the links on pages if it is simple '**a:href**' or it is xHTML 'ac:link'. The Confluence wise links are of ac:link type.


author: Andrii Maliuta
body: ***\>\> You mentioned that it's possible to change the links with apps. Do you know by change an app that can do that***

Yes, you just need to change the format of the link inside page body.

* get pages with links
* get pages bodies
* replace href format with ac:link format
* save changes on pages

For this you can use tools ScriptRunner with Java API or any HTP client and REST API.


author: Dominik Gashi
body: Thank you [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201) !  
I tested it out and it worked.


Tags: confluence-server

server