$Web Redirect: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:$Web_Redirect}}
{{DISPLAYTITLE:$Web_Redirect}}
<span class="pageSubtitle"><section begin="desc" />Re-route client to another server<section end="desc" /></span>
<span class="pageSubtitle">Re-route client to another server</span>


<var>$Web_Redirect</var> re-routes the client to another server.


<var>$Web_Redirect</var> is a [[Calling_Sirius_Mods_$functions|callable]] $function, and it takes a single required string argument and returns a status code.


$Web_Redirect re-routes the client to another server.
==Syntax==
==Syntax==
<p class="syntax"><section begin="syntax" /> %RC = $Web_Redirect( url )
<p class="syntax"><span class="term">%rc</span> = <span class="literal">$Web_Redirect</span>(<span class="term"> url</span> )
<section end="syntax" /></p>
</p>


===Syntax terms===
<table class="syntaxTable">
<tr><th nowrap>%rc</th>
<td>A numeric [[#Status codes|status code]].


$Web_Redirect is a callable $function (see [[Calling_Sirius_Mods_$functions|"Calling Sirius Mods $functions"]]), and it takes a single required string argument and returns a status code.
<table class="syntaxTable">
<tr><th>url</th>
<tr><th>url</th>
<td>An absolute or relative Universal Resource Locator (URL). ''url'' must be non-null (in order for the browser to complete the redirection request). <blockquote>Under ''[[Sirius Mods]]'' Version 6.7 and later, this argument may be a longstring with a length greater than 255 bytes.</blockquote>
<td>An absolute or relative Universal Resource Locator (URL). ''url'' must be non-null (in order for the browser to complete the redirection request).  
</td></tr></table>
<p class="note">
'''Note:''' This argument may be a longstring with a length greater than 255 bytes.</p>
</td></tr>
</table>


===Status codes===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>Code</th>
<tr><th>Code</th>
<td>Meaning</td></tr>
<th>Meaning</th></tr>
<tr><th>0</th>
<tr><th>0</th>
<td>Redirection request initiated.</td></tr>
<td>Redirection request initiated.</td></tr>
Line 25: Line 32:
<tr><th>-3</th>
<tr><th>-3</th>
<td>Invalid URL or missing argument</td></tr>
<td>Invalid URL or missing argument</td></tr>
</table>
</table>
<p class="caption">$WEB_REDIRECT return codes</p>
If the input URL is absolute, processing can be redirected to a different machine or a different port on the same machine (for example, an SSL port). If the URL is relative (no hostname specified), processing is re-directed to the same port but for a different URL. While this might seem like an odd thing to do, it can actually be quite useful for a couple of reasons.
<ol>


==Usage notes==
<ul>
<li>If the input URL is absolute, processing can be redirected to a different machine or a different port on the same machine (for example, an SSL port). If the URL is relative (no hostname specified), processing is re-directed to the same port but for a different URL. While this might seem like an odd thing to do, it can actually be quite useful:
<ul>
<li>Browsers cache data based on the URL that actually return data so if the output from several different URLs produce the same output, it can be more efficient for these URLs to all redirect to the same URL than for the each URL to send the response data without a redirect.  
<li>Browsers cache data based on the URL that actually return data so if the output from several different URLs produce the same output, it can be more efficient for these URLs to all redirect to the same URL than for the each URL to send the response data without a redirect.  
<li>It can simplify coding: one part of an application might process input and then redirect to a separate application that sends a web page to the browser.
<li>It can simplify coding: one part of an application might process input and then redirect to a separate application that sends a web page to the browser.
</ol>
</ul>
 
</ul>
 


==Examples==
Sample code follows:
Sample code follows:
<p class="code"> %DOWNLOAD_TYPE = $Web_Form_Parm('DOWNLOAD_TYPE')
<p class="code">%DOWNLOAD_TYPE = $Web_Form_Parm('DOWNLOAD_TYPE')
   
   
IF %DOWNLOAD_TYPE EQ 'FTP' THEN
IF %DOWNLOAD_TYPE EQ 'FTP' THEN
IF $Web_Form_Parm('LOCATION') EQ 'USA' THEN
IF $Web_Form_Parm('LOCATION') EQ 'USA' THEN
%X = $Web_Redirect('ftp://www.widgets.usa.com')
%X = $Web_Redirect('ftp://www.widgets.usa.com')
ELSE
ELSE
%X = $Web_Redirect('ftp://www.widgets.ja')
%X = $Web_Redirect('ftp://www.widgets.ja')
END IF
END IF
END IF
END IF
</p>
</p>


In this example, users that specified a 'DOWNLOAD_TYPE' of 'FTP' on their form are routed to either the Widget Company's USA ftp server or their international server in Japan, depending on the contents of the LOCATION form field.
In this example, users that specified a 'DOWNLOAD_TYPE' of 'FTP' on their form are routed to either the Widget Company's USA ftp server or their international server in Japan, depending on the contents of the LOCATION form field.


[[Category:Janus Web Server $functions|$Web_Redirect]]
[[Category:Janus Web Server $functions|$Web_Redirect]]

Latest revision as of 22:22, 15 January 2016

Re-route client to another server

$Web_Redirect re-routes the client to another server.

$Web_Redirect is a callable $function, and it takes a single required string argument and returns a status code.

Syntax

%rc = $Web_Redirect( url )

Syntax terms

%rc A numeric status code.
url An absolute or relative Universal Resource Locator (URL). url must be non-null (in order for the browser to complete the redirection request).

Note: This argument may be a longstring with a length greater than 255 bytes.

Status codes

Code Meaning
0 Redirection request initiated.
-1 Invalid call, not a Web thread
-3 Invalid URL or missing argument

Usage notes

  • If the input URL is absolute, processing can be redirected to a different machine or a different port on the same machine (for example, an SSL port). If the URL is relative (no hostname specified), processing is re-directed to the same port but for a different URL. While this might seem like an odd thing to do, it can actually be quite useful:
    • Browsers cache data based on the URL that actually return data so if the output from several different URLs produce the same output, it can be more efficient for these URLs to all redirect to the same URL than for the each URL to send the response data without a redirect.
    • It can simplify coding: one part of an application might process input and then redirect to a separate application that sends a web page to the browser.

Examples

Sample code follows:

%DOWNLOAD_TYPE = $Web_Form_Parm('DOWNLOAD_TYPE') IF %DOWNLOAD_TYPE EQ 'FTP' THEN IF $Web_Form_Parm('LOCATION') EQ 'USA' THEN %X = $Web_Redirect('ftp://www.widgets.usa.com') ELSE %X = $Web_Redirect('ftp://www.widgets.ja') END IF END IF

In this example, users that specified a 'DOWNLOAD_TYPE' of 'FTP' on their form are routed to either the Widget Company's USA ftp server or their international server in Japan, depending on the contents of the LOCATION form field.