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

Problem with redirection of sites to different pages

Hi Friends,
please help me..its very urgent...

I have been trying to redirect site to the url given.
For example if we take salesforce if i give account details page url page and login with the credentials it goes to the particular account detail page, i want the same functionality in sites.

For that i have written the below code...its working for every page except the event detailpage( url is

* An apex page controller that exposes the site login functionality
global class SiteLoginController {

    //Properties to store username and password entered by the user
    global String username {get; set;}
    global String password {get; set;}
    global String profileName {get; set;}
    global String urlredirect {get; set;}
    global String urlredirectSF {get; set;}
    global String urlredirectSFbase {get; set;}
     global SiteLoginController()
       urlredirect= URL.getCurrentRequestUrl().toExternalForm();
       urlredirectSF= URL.getSalesforceBaseUrl().toExternalForm();
       urlredirectSFbase= string.valueof(URL.getSalesforceBaseUrl());
    //Method to check the username and password. It will throw error if the username/password is incorrect
    global PageReference login() {
        //Setting profile Name
        profileName = '';
        //Setting start URL
        String startUrl = '/apex/FLIPHome';
        String flipredirect = '/apex/'+urlredirect.subStringAfter('FLIP/');
       // String eventurl ='apex/Eventdetails/'+urlredirect.subStringBetween('Events','&');
       // String eventurl ='apex/Eventdetails/'+urlredirect.subStringAfter('/Events')+'showComments=true';
     //   String eventurl ='/apex/EventDetail/'+urlredirect.subStringAfter('FEvents');
    //   system.debug('----eventurl----'+eventurl);
    //   system.debug('----flipredirect----'+flipredirect);
       //Query Profile Name
       List<User> loginUser = [select ProfileId,username,Profile.Name from user where Username = :username];
       profileName = loginUser[0].Profile.Name;
       system.debug('-------Profile Name--------'+ profileName);
       if(profileName.equals('FLIP Participant') || profileName.equals('Readonly Participant'))
          system.debug('-------coming to login-------'+ urlredirect);
          return Site.login(username, password, startUrl  );
   /*  else if(urlredirect.contains('EventDetail'))
          system.debug('-------coming to event-----'+ urlredirect);
         return Site.login(username, password, eventurl  );
         } */
         else  { system.debug('value of startURL.....'+flipredirect);
         return Site.login(username, password, flipredirect );
       else if(profileName.equals('Executive Coach'))
        startUrl = '/apex/MarketplaceHome';
        return Site.login(username, password, startUrl );
       else if(profileName.equals('LI Participant'))
        startUrl = '/apex/LIHome';
        return Site.login(username, password, startUrl );
       return Site.login(username, password, startUrl);

Is there any problem with my code??????????
Or please suggest how can I navigate to a page based on URL....
Waiting for your help guys.......................
Hi , 

Try it out.

Site s = [SELECT s.Subdomain FROM Site s LIMIT 1 ];
String urlCode = String.valueof(URL.getSalesforceBaseUrl().toExternalForm());
String [] cuts = urlCode.split('[.]');
urlCode = '';
for(Integer i = 1; i < cuts.size(); i++){
        urlCode += cuts[i] + '.';
urlCode = urlCode.substring(0, urlCode.length()-1); 
urlCode = 'https://'+s.Subdomain+'.'+urlCode+'/yourpage;

Also see the below links with more information and related threads,

Also, Vote for this Idea,