Skip to content

Redirection Rules

How redirection rules work in ExeOutput for PHP

Using redirection in ExeOutput for PHP enables you to redirect users from an old page to a new page or, in case of frameworks,. redirect all requests to a router script.

Warning

By default, redirection support is disabled. You have to enable this feature in ExeOutput for PHP by going to PHP Settings => Main Settings and ticking Enable custom router handler in HEScript (OnRouterURL event).

Info

If you do not need redirection, leave this feature off because it can slightly.increase the internal server's processing time.

Adding redirection rules

Once the redirection support is enabled, for each request made to the server, an HEScript event named OnRouterURL available in the UserMain script will be invoked.

If you take a look at the UserMain script below:

img

function OnRouterURL(RequestedURL, RequestedFilename, PathInfo, QueryString: String): String;

The following parameters are passed:

  • RequestedURL contains the full request URL.
  • RequestedFilename represents the virtual path to the requested file.
  • PathInfo represents the value of the PATH_INFO variable as defined for PHP. That is any client-provided pathname information trailing the actual script filename but preceding the query string, if available.
  • QueryString contains the query string, if any (text after ? in URL).

The engine will perform a redirection only if Result is set to the new URL. For no redirection, just return an empty string.

Example of redirection

The router script (which is also the homepage) is public\index.php. The framework we use in this sample generates some URLs like http://heserver/public/index.php/assets/image.png. Of course, the Chromium engine cannot find these URLs, so we rewrite them:

 function OnRouterURL(RequestedURL, RequestedFilename, PathInfo, QueryString: String): String; 
begin
 // Lets you reroute any URL.
 if (RequestedFilename = "public\index.php") and (ExtractFileExt(PathInfo) <> "") then
 begin           
  Result:="http://heserver/public" + PathInfo;
  exit;
 end;
 // Set Result to an empty string for no redirection.
 // Set Result to the new URL if you want a permanent redirection.           
 Result := "";
end;     
For instance, the script above will transform the following URL: http://heserver/public/index.php/assets/image.png into http://heserver/public/assets/image.png