Proxy in Virtual Directory and Redirecting problem

Mar 3, 2010 at 6:24 AM

Hi,

I have successfully installed this proxy. I installed it in IIS 5.1 in Windows XP. I didn't install it under website but under a Virtual Directory.

I've also created a rule and it successfully executed, for example, I use this rule to proxy wikipedia web site: RewriteRule ^(.*)/wiki/(.*)$               http://en.wikipedia.org/wiki/$2   [NC,P,QSA]
to access the site thru proxy is by typing this in address bar: http://mysite/Proxy/wiki/

The problem is when i tried to access other web site (this is an internal application using ASP.NET, located in other server)
The rule is like this: RewriteRule RewriteRule ^(.*)/sub1/(.*)$    http://othersite/sub1/$2   [NC,P,QSA]
and to access it by typing: http://mysite/Proxy/sub1/sub2/authenticate.aspx?param1=xxxx&param2=yyyy&param3=zzzz

at first, It successfully executed the authenticate.aspx. the proxy redirecting to the real address which is http://othersite/sub1/sub2/authenticate.aspx?param1=xxxx&param2=yyyy&param3=zzzz
but, inside the authenticate.aspx, there is a command that redirect to other page, for example: Response.Redirect("page2.aspx").

This is when the problem occur. In the address bar the link is became: http://mysite/page2.aspx (as you can see, there is no "Proxy" section), which cause a "The resource cannot be found." error.
the link should be http://mysite/Proxy/page2.aspx, because I set the proxy under "Proxy" virtual directory not the Home directory.

Does anyone know the solution for this? i don't want to change the codes in the target application.
Perhaps, there is a rule that can resolve this problem.

Thanks. 

Mar 3, 2010 at 8:49 AM

Hi, 

I've also noted that if I access wiki thru proxy: http://mysite/Proxy/wiki/, it can be displayed but the links inside the main page are still linked to http://mysite/<links> (no "Proxy" directory).

Does this mean that we can't install the component in the sub directory, i.e must be in root directory? or perhaps it can but my configuration is still wrong.

Thanks.

Coordinator
Mar 4, 2010 at 2:37 PM

A proxy simpling transmits the content from a internal site to an external site.  It doesn't modify any content in the body of the request.  If you need the content in the body of your request modified you have to use some kind of post processing request.

There is a beta feature in the latest version of the rewriter that does this to some extent.  Try adding the following to your site.

OutRewriteRule ^href="http://mysite/([^"]*)"   href="http://mysite/Proxy/$1"  [NC,L]

I am not sure about the rules that I put above you will have to play with them.

Mar 5, 2010 at 2:32 AM

Hi Nick,

Thanks for the reply. I'll try this. Does the beta feature is already available in the latest stable download? Url Rewriter 3.5, Dec 3 2009, Stable (http://urlrewriter.codeplex.com/releases/view/36792#DownloadId=95504)
or, I need to download the latest source code (56108, http://urlrewriter.codeplex.com/SourceControl/list/changesets#) and compile it. btw, when I compile the source code it look snk file which does not exist. Can you provide one?

Thanks and Best Regards, 

Mar 5, 2010 at 6:52 AM

Hi Nick,

I'm using the latest binaries download (Url Rewriter 3.5 Stable). and I have tried using OutRewriteRule, and it doesn't work.

I implement a basic rule, every "/ (quote followed by slash) strings replace with " (quote only). The result should be: from "/Page1.aspx" will become "Page1.aspx". (Between the text can be anything). These is the content of the rules file:

 

RewriteEngine On

RewriteLog "/Website/log.txt"
RewriteLogLevel 9

OutRewriteRule ^"/([^"]*)"              "$1"                                [NC,L]
RewriteRule ^/website/wiki/(.*)$	http://en.wikipedia.org/wiki/$1	    [NC,P,QSA]

I test opening a wiki page, but it seems the links inside the page are not changed.

I have tried to put the OutRewriteRule before and after the RewriteRule for wiki, but it still doesn't work.

Perhaps the rule was wrong. Please help.

Thanks & Best Regards,

 

Coordinator
Mar 5, 2010 at 12:07 PM

Like I said it was a beta feature, and I am not quite ready to support it yet.  I thought it may work for you.  Also try putting the OutRewriteRule at the bottom.  Doubt it will help but you can try.  Also this is a new feature for Rewriter 3.5 so make sure you are using that.  Also I saw that you fixed your issue over here:

http://urlrewriter.codeplex.com/Thread/View.aspx?ThreadId=203754

Hope everything is working as expected now.

Mar 6, 2010 at 12:47 PM
Edited Mar 6, 2010 at 1:15 PM

Hi Nick,

I'm able to compile your source code and debug it. and I think there is a problem with my regex. Will play around with it to find a right one.

Btw, I've also found out that to make the OutRewriteRule works, we need to set allowOutputProcessing to true in the web.config at:

 

	<managedFusion.rewriter xmlns="http://managedfusion.com/xsd/managedFusion/rewriter">
		<rules engine="Apache" allowOutputProcessing="true" />
	</managedFusion.rewriter>

 

and, I've also found a bug in the code. That's why the OutRewriteRule doesn't work (beside my regex is still wrong).

It's in the ApacheRuleSet class in RefreshRules(TextReader reader) method at line: 700 and 780. Just a small bugs, you put the wrong variable. it should be OutRewriteRuleLine (for line 780) and OutRewriteCondLine (for line 700). Please check again, incase i was wrong.

Btw, I think this software is great.

For my other thread, I think i'm not going to use that method for now. I'm going to try to use OutRewriteRule to change the content of page.

Thanks for your help..

Best Regards.

Coordinator
Mar 6, 2010 at 8:48 PM

Thanks I forgot about that you had to enable it.  It has been about 2 months since I worked on the feature.  Also thanks for the report, I have logged the issue.

 

 

Coordinator
Mar 6, 2010 at 8:49 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.