/
redirect.yaws
108 lines (83 loc) · 2.79 KB
/
redirect.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<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>
</div>
<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>