+ 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.




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 -





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






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

      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).