[SalesForce] How to pass multiple parameters on an outputlink

I'm using the following Visualforce code to send multiple parameters (including a returl) to a controller.

<apex:outputLink target="_blank"  styleClass="btn addToBtn2" 
value="/apex/NewScholarRequest?SiteID={!selectedProgram}?returl=/apex/be1_Attendance{!URLENCODE('?cy='+selectedCycle+'&di='+selectedDistrict+'&si='+selectedProgram)}">
New Scholar Request
</apex:outputLink>  

When I try to get the result in the controller constructor, I get:

tmp =  apexpages.currentpage().getparameters().get('siteID');

I get this result:

siteID=a0Z00000001BwnWEAS?returl=/apex/be1_Attendance?cy=a0J00000000hIKOEA2&di=a0K00000000dtALEAY&si=a0Z00000001BwnWEAS

That's the whole set of parameters, not just the first one. Why don't they get split up? Do I need to individually URLENCODE each parameter after the first?

Best Answer

The URLENCODE call will encode the ? and & delimiters whereas you really need to just encode each parameter.

One way to do that is:

"/apex/be1_Attendance?cy={!URLENCODE(selectedCycle)}&di={!URLENCODE(selectedDistrict)}&si={!URLENCODE(selectedProgram)}"