Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

URL Redirection API

Ravi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 5, 2018

Hi,

 

I am trying to develop a plugin that allows space administrators to implement URL redirection at a space level in Confluence. I would like to know if there is any API available which does the needful.

Here is an example for my use case:

User enters the following URL in the browser: https://www.example.com/test

He should be redirected to the space: https://www.example.com/display/test123

 

Thanks, in advance.

2 answers

0 votes
Dmitry January 21, 2022

We can create listener :

package <package>.listener;

import com.atlassian.confluence.event.events.content.page.PageViewEvent;
import com.atlassian.confluence.pages.Page;
import com.atlassian.event.Event;
import com.atlassian.event.EventListener;
import com.opensymphony.webwork.ServletActionContext;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

public class PageListener implements EventListener {

private static final Class[] HANDLED_EVENTS = new Class[] {
PageViewEvent.class
};

public void handleEvent(Event event) {
if (event instanceof PageViewEvent) {
PageViewEvent pageViewEvent = (PageViewEvent) event;
Page page = pageViewEvent.getPage();
if (page.getNameForComparison().equals("test")) {
HttpServletResponse response = ServletActionContext.getResponse();
try {
response.sendRedirect("/display/test123");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

public Class[] getHandledEventClasses()
{
return HANDLED_EVENTS;
}
}

More about listeners:

https://developer.atlassian.com/server/confluence/writing-an-event-listener-plugin-module/ 

0 votes
Bill Bailey
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.
December 7, 2018

IRC, there was a page redirect macro within Confluence, but was recently deprecated. I see on the marketplace that someone has jumped in to fill that void: redirection-for-confluence

Ravi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2018

Hi Bill,

 

Thanks for your response. Unfortunately, the redirection macro wouldn't solve my use case.

I would like to know if there is any java API provided by Confluence to implement the redirection.

 

Regards,

Ravi

Bill Bailey
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.
December 13, 2018

Well maybe this is a job for the web proxy, set up redirection there. For example, using mod_rewrite rules. That would be far easier to set up and respond more quickly.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events