
<erl>

out(A) ->
       {ssi, "TAB.inc","%%",[{"redirect", "choosen"}]}.

</erl>

<div id="entry">

<h2>Redirects</h2>

<p> Redirs are a powerful tool in the webapp programmer toolbox. The
Webserver returns a specific status code (302) and adds a
"Location:" header
to the responce headers to the Browser. The Browser then displays the new
page as indicated in the "Location" header.</p>

<p> Yaws supports a number of different forms of redirect return values
from the out/1 function.</p>
<p>
The code:</p>

<erl>
out(_A) ->
        {ehtml,
        {'div', [{class,"box"}],
         {pre,[],
          {ssi, "redirect2.yaws",[],[]}}}}.
</erl>

<p> Clickable <a href="redirect2.yaws"> On this link </a> executes the
  above redirect code.
</p>

<p> The code above redirects to an external URL. The HTTP RFC mandates
  that the Loction header must contain complete URLs, including the
  the method, http, https etc. A very common case of redirection, is
  a to redirect to another file on the same server. The code
  in <a href="redirect3.yaws"> redirect3.yaws </a> shows an example of
  a yaws redirect relative to the "current" server.
</p>

<erl>
out(_A) ->
        {ehtml,
        {'div', [{class,"box"}],
         {pre,[],
          {ssi, "redirect3.yaws",[],[]}}}}.
</erl>


<p> The code in <a href="redirect3.yaws"> redirect3.yaws </a> will
  do a relative redirect to the code in
  <a href="redirect2.yaws"> redirect2.yaws </a> which in its turn
  redirects, once again, to google. Double redirects.
</p>

<p>While working with redirects, the tool <a href="http://curl.haxx.se/"> curl </a>
is an excellent way to troubleshoot the behaviour of your
redirects. For example:</p>

<div class="box">
  <verbatim>

    # curl -I http://rubin.hyber.org:8000/redirect3.yaws

    HTTP/1.1 302 Found
    Server: Yaws/1.49 Yet Another Web Server
    Location: http://rubin.hyber.org:8000/redirect2.yaws
    Date: Tue, 16 Nov 2004 20:16:01 GMT
    Content-Type: text/html

  </verbatim>
</div>

  <p>Where <tt> http://rubin.hyber.org:8000</tt> is where I am currently
    testing the <a href="redirect3.yaws"> redirect3.yaws </a> code.
    Learn and use the <a href="http://curl.haxx.se/"> curl </a>
    web client, it may not render pictures pretty, but it sure displays
    headers.
  </p>
  <br />

  <p> We show one additional version of redirect code. The code in
    <a href="redirect3.yaws"> redirect3.yaws </a> requires an absolute path.
    If we want to supply a path relative to the current url, we can use
    either the Redirect modifier <tt>rel_path</tt> or <tt>any_path</tt>
    as in :
  </p>

<erl>
out(_A) ->
        {ehtml,
        {'div', [{class,"box"}],
         {pre,[],
          {ssi, "redirect4.yaws",[],[]}}}}.
</erl>

<p> <a href = "redirect4.yaws"> Clickable here </a>
</p>

<p>You can also redirect a whole site via virtual server configuration. For
example, you can redirect all port 80 requests to port 443 like this:</p>

<div class="box">
  <verbatim>
    <server vhost1.tld>
       port   = 80
       listen = 0.0.0.0
       <redirect>
         / = https://vhost2.tld:443
       </redirect>
    </server>
  </verbatim>
</div>

</div>


<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>
