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
Dovid BDovid B 

URL redirect with GET parameters

Normally speaking in order to do a 301 redirect from a URL with parameters, you need to modify .htaccess with a rewriteCond as seen here for example.

 

Since, as far as I have seen, we don't have access to .htaccess in Sites. Anybody come up with a good way to redirect a URL with parameters? Preferably a way to transfer those parameters to the new URL.

 

Thanks.

bob_buzzardbob_buzzard

You can redirect from a Visualforce sites page using a page action method - this specifies a method on your controller that is invoked prior to rendering the page, allowing you to redirect the user.

 

You can add parameters to the URL via PageReference.getParameters().

 

Here's a noddy example -

 

Page:

 

 

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

 

 

Controller

 

 

public class MyController
{
   public PageReference redirect()
   {
      PageReference result=Page.NextPage;
      result.getParameters().put('param1', 'value1');
      result.getParameters().put('param2', 'value2');
      result.setRedirect(true);

      return result;
   }
}

 

Make sure you use the setRedirect(true) mechanism, or the redirect doesn't take place (at least that's what I've found today).