anchor.diff:  %% we must deliver a 302 if the browser asks for a dir
   %% without a trailing / in the HTTP req
   %% otherwise the relative urls in /dir/index.html will be broken.
  +%% Note: Here Path is always decoded, so we must encode it
   deliver_302(CliSock, _Req, Arg, Path) ->
       ?Debug("in redir 302 ",[]),
       H = get(outh),
       SC=get(sc),
       Scheme  = yaws:redirect_scheme(SC),
       Headers = Arg#arg.headers,
  -    DecPath = yaws_api:url_decode(Path),
  +    EncPath = yaws_api:url_encode(Path),
       RedirHost = yaws:redirect_host(SC, Headers#headers.host),
   
       %% QueryString must be added
       Loc = case Arg#arg.querydata of
  -              undefined -> ["Location: ", Scheme, RedirHost, DecPath, "\r\n"];
  -              [] -> ["Location: ", Scheme, RedirHost, DecPath, "\r\n"];
  -              Q -> ["Location: ", Scheme, RedirHost, DecPath, "?", Q, "\r\n"]
  +              undefined -> ["Location: ", Scheme, RedirHost, EncPath, "\r\n"];
  +              [] -> ["Location: ", Scheme, RedirHost, EncPath, "\r\n"];
  +              Q -> ["Location: ", Scheme, RedirHost, EncPath, "?", Q, "\r\n"]
             end,
       new_redir_h(H, Loc),
       deliver_accumulated(CliSock),
  
positive.code:                      {_Prefix, Code, Path, Mode}, N) when is_list(Path) ->
      %% Here Code is 1xx, 2xx, 4xx or 5xx
      ?Debug("in redir ~p", [Code]),
      DecPath = safe_decode_path(Req#http_request.path),
      Page = if
                 Mode == append ->
                     filename:join([Path ++ DecPath]);
                 true -> %% noappend
                     case yaws:split_at(DecPath, $?) of
                         {_, []} -> Path;
                         {_, Q}  -> Path ++ "?" ++ Q
                     end
             end,
  
      %% Set variables used in handle_method_result/7
  
negative.code:     %% Here Code is 3xx
      ?Debug("in redir ~p", [Code]),
      H = get(outh),
      QueryData = case Arg#arg.querydata of
                      undefined -> [];
                      Q         -> Q
                  end,
      LocPath = if
                    Mode == append ->
                        EncPath = yaws_api:url_encode(Arg#arg.server_path),
                        Path1   = filename:join([URL#url.path ++ EncPath]),
                        yaws_api:format_partial_url(
                          URL#url{path=Path1,querypart=QueryData}, get(sc)
                         );
                    true -> %% noappend
                        yaws_api:format_partial_url(URL#url{querypart=QueryData},
                                                    get(sc))
                end,
      Loc = ["Location: ", LocPath, "\r\n"],
  
      {DoClose, _Chunked} = yaws:dcc(Req, Arg#arg.headers),
      new_redir_h(H#outh{
                    connection = yaws:make_connection_close_header(DoClose),
  