0

I have a Community setup and I am trying to redirect an incoming page request. For example,"http://xxxx.xxx.force.com/xxxx/xxxx/Article/448" would need to be redirected to "http://xxxx.xxx.force.com/s/Article/448".

I currently have some Javascript that is able to parse the "448" out of the current URL using "window.location.href" and I am able to redirect using this approach. My question is, how would I do this server side using APEX?

I have tried to use the "ApexPages.currentPage().getURL();" but this is only returning parameters (Anything after a "?") and I need to the full relative path. (/xxxx/xxxx/Article/448)

Thank you for any information.

West

  • Have you peeked at URL Rewriting with Sites? – sfdcfox Sep 8 '15 at 17:31
  • @sfdcfox This is what I am also looking for. For me somehow URL Rewriter Class didn't work. Can you please help us out. I have implemented a workaround solution posted as below. – Saroj Bera Sep 8 '15 at 18:06
0

Here is a solution which is working for me. You have to update URL Rewriter Class for the site as below. The URL Rewriter Class will forward to VF page and intern redirect to the Site.com page.

But ultimately Salesforce generate some JavaScript to do the re-direction.

URL Rewriter Class

global class MySiteURLRewritter implements Site.UrlRewriter {
    global PageReference mapRequestUrl(PageReference requestPage){
        Pagereference targetURL=null;
        if(URL.getSalesforceBaseUrl().toExternalForm().endsWith('/Article/448')){
            targetURL = new PageReference('/QUODSiteURLRewritter?url='+EncodingUtil.urlDecode('/s/Article/448','UTF-8'));
        }
        return targetURL;
    }
    public PageReference redirect(){
        return new PageReference(ApexPages.currentPage().getParameters().get('url'));
    }
}

Vf Page

<apex:page controller="MySiteURLRewritter" action="{!redirect}"></apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.