function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakshana Cube84Rakshana Cube84 

Get the current page URL from Community portal VF page

Hi All,

We have implemented a community portal which runs public. In that community branding, we have added a developed Visualforce page which fetches the current URL by using ApexPages.Currentpage().getParameters().get('referer') and we have few links in the visualforce page to redirect a page which already been created as a community page. We are getting the URL properly for some time. But some moment, it returns the random related URL when we play around with the site. 
Please help us to get the exact URL for all time.
Deepali KulshresthaDeepali Kulshrestha
Hi Rakshana,

Greetings to you!
Please try this code as it may help you in solving your problem. Here is the Link/Button, on click of that calls the javascript method.
<input type="button" value="Proceed" onclick="redirectToMyPageJS();" />

My JS function which gets the community name from the URL:

    function redirectToMyPageJS()
        // It's always the 3rd element in the list which is the community name when accessed from the communities site

and calls my action function passing the community name as a parameter:

<apex:actionFunction action="{!redirectToMyPage}" name="redirectToMyPage" >
    <apex:param value="" name="portalName" />

Then in APEX method put:

public pageReference redirectToMyPage()
    return new PageReference('/' + Apexpages.currentPage().getParameters().get('portalName') + '/MyOtherPage');

change it according to your needs.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha