Rewrite module

klacke edited this page Sep 13, 2010 · 1 revision

arg_rewrite_mod = rewriter

between the virtual server definition in the yaws.conf file.

For example:

<server localhost>
  port = 8080
  listen = 0.0.0.0
  docroot = /var/www/yaws-default
  arg_rewrite_mod = rewriter
</server>


Below is an example/template of how I managed to get something working. I’m not sure if this is the ‘right’ way to do it however.. Feel free to comment & improve/replace it.

……

-module(rewriter).

-export([arg_rewrite/1]).

-include_lib("yaws/include/yaws_api.hrl").

arg_rewrite(ARG) ->
        Req = ARG#arg.req,
        case Req#http_request.path of
        {abs_path, RawPath} ->
		case (catch yaws_api:url_decode_q_split(RawPath)) of
		{'EXIT', _} -> %%broken request - ignore let yaws_server handle it.
			ARG2 = ARG;
		{DecPath, QueryPart} ->
		 	Parts = string:tokens(DecPath,"/"),	
			case lists:member("viewvc",Parts) of
			true ->
		
				%%
				%Do something with DecPath & QueryPart
				%
				case QueryPart of
				[] ->
					%% Rewritten = SomeNewpath;
				_Other ->
					%% Rewritten = SomeNewpath ++ "?" ++ QueryPart
				end,
				%
				%%	

			  	Req2 = Req#http_request{path = {abs_path, Rewritten}},

				ARG2 = ARG#arg{req = Req2};			
			false -> 		
				ARG2 = ARG
			end	
		end;
        _Else ->
		ARG2 = ARG
        end,	

        ARG2.

……

Great job! I improved the code to make Yaws work with PHP Zend Framework. Go to http://forum.trapexit.org/viewtopic.php?t=14964 for more information. It is quite possible that it will also work for other frameworks (like Cake, for example) – though I haven’t tested it personally.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.