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.
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
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
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.
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/
It looks like you're new here. Sign in or register to get started.