help with rewrites

Topics: User Forum
Sep 15, 2009 at 2:49 PM

I'm new to this filter and not really good with regex yet.  I'd like to replace my current filter, and this version looks like my best option.

I need to rewrite my urls similar to the sample, TransformUrlSegmentsToQueryParamsIteratively2.

www.domain.com/exec/action/verb

www.domain.com/exec

www.domain.com

www.domain.com/rdr/content/value

My url can contain 1-many paired querystring parameters separated with /.  I currently have 2 pages to rewrite.  rdr = Redirect.aspx and exec = default.aspx.

However, if the url doesn't contain rdr, I'd be fine with just ignoring/dropping any reference to exec and appending default.aspx to the url.  That way I can eventually remove exec from my urls entirely.  I also need this to work on my development site at localhost/folder/exec

 

Coordinator
Sep 15, 2009 at 4:00 PM

The example you cited comes pretty close to what you want.  What problem are you having?

 

Sep 15, 2009 at 4:18 PM
Edited Sep 15, 2009 at 4:38 PM

Regex isn't my strongest area.

This is what I've got.

# handle case with no query string . This rule fires the first time through.

RewriteRule ^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)$ /$3?$1=$2 [I,L]

# handle case with existing query string. This rule fires potentially multiple times.

RewriteRule ^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)\?(.+)$ /$3?$4&$1=$2 [I,L]

# Handle the case with one more pair of segments. This fires once (last).

# It fires when there is an even number of segments.

RewriteRule ^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)\?([^\?]+)$ /default.aspx?$3&$1=$2 [I,L]

# Handle the case with exactly one pair of segments. This fires once (last).

RewriteRule ^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)$ /default.aspx?$1=$2 [I,L]

# Handle the edge case, where there is an odd number of segments (invalid input URL)

# This fires once, after all the other pairs have been parsed. In fact the filter

# cannot know that there is an odd number of segments until it does all the matching.

# So at the end we see, we have one left over segment, and we

# redirect to a 404 page.

RewriteRule ^/(?!default\.aspx)([^\/\?]+)\?([^\?]+)$ /_hpError404.aspx [I,L]

# Handle the edge case where there is only one segment.

RewriteRule ^/(?!default\.aspx^\/\?]+)$ /_hpError404.aspx [I,L]

I'd also like to pass through any requests made directly to *.aspx, *.asmx, etc, with or without a querystring.  The last thing I want to accomplish is redirecting any requests to domain.com to www.domain.com, but not other sub-domains such as blog.domain.com.

I tried adding your example from http://iirf.codeplex.com/Thread/View.aspx?ThreadId=60845 above the other Rules, but I don't think thy were working correctly.

# static content

#RewriteCond %{QUERY_STRING} ^$

#RewriteRule /(.+)\.(css|gif|jpeg|jpg|ico|png|htm|html|js|txt|xml|asmx)$ /$0 [I,L]

# aspx with empty query string

#RewriteCond %{QUERY_STRING} ^$

#RewriteRule ^/((.+)\.aspx$)([^\?\/]+)/([^\?\/]+)/([^\?]+)$ /$3?$1=$2 [I,L]

# aspx with non-empty query string

#RewriteCond %{QUERY_STRING} ^.+$

#RewriteRule ^/((.+)\.aspx\)([^\?\/]+)/([^\?\/]+)/([^\?]+)\?(.+)$ /$3?$4&$1=$2 [I,L]

I did comment them out.

I've got two other quick questions. I can't seem to open the help file, IirfGuide.chm, in Windows XP, I get Navigation errors. Is there a known problem? Second, I was going to use v2 of the filter, but the logging feature doesn't seem to work?

Here's my output from the log file.


--------------------------------------------
Tue Sep 15 11:07:09 - 4776 - ReadConfig: setting LogLevel to 5
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 14: StatusUrl /iirfStatus
Tue Sep 15 11:07:09 - 4776 - ReadConfig: StatusUrl is enabled for local requests only.
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 32: RewriteRule (rule 1) '^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)$' '/$3?$1=$2' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 35: RewriteRule (rule 2) '^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)\?(.+)$' '/$3?$4&$1=$2' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 40: RewriteRule (rule 3) '^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)\?([^\?]+)$' '/default.aspx?$3&$1=$2' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 43: RewriteRule (rule 4) '^/(?!default\.aspx)([^\?\/]+)/([^\?\/]+)$' '/default.aspx?$1=$2' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 53: RewriteRule (rule 5) '^/(?!default\.aspx)([^\/\?]+)\?([^\?]+)$' '/_hpError404.aspx' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: line 56: RewriteRule (rule 6) '^/(?!default\.aspx^\/\?]+)$' '/_hpError404.aspx' [I,L]
Tue Sep 15 11:07:09 - 4776 - ReadConfig: not a duplicate rule...
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: '[I,L]'
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'I'
Tue Sep 15 11:07:09 - 4776 - rule: Case Insensitive match
Tue Sep 15 11:07:09 - 4776 - ParseRuleModifierFlags: token 'L'
Tue Sep 15 11:07:09 - 4776 - rule: Last
Tue Sep 15 11:07:09 - 4776 - ReadConfig: Done reading, found 6 rules (0 errors, 0 warnings) on 59 lines

--------------------------------------------
Tue Sep 15 11:07:09 - 4776 - Initialize: Ionic ISAPI Rewriting Filter (IIRF) v1.2.16 R8
Tue Sep 15 11:07:09 - 4776 - Initialize: config file 'C:\WINDOWS\system32\inetsrv\IIRF\IsapiRewrite4.ini'
Tue Sep 15 11:07:09 - 4776 - Initialize: File watcher thread created.
Tue Sep 15 11:07:09 - 4776 - GetFilterVersion
Tue Sep 15 11:07:09 - 5740 - FileChangeWatcher(): Enter
Tue Sep 15 11:07:09 - 5740 - FileChangeWatcher: Await()...
Tue Sep 15 11:07:09 - 5740 - AwaitIniChangeAndReinit()...
Tue Sep 15 11:07:10 - 3948 - DllMain THREAD_DETACH
Tue Sep 15 11:08:56 - 5680 - HttpFilterProc: SF_NOTIFY_URL_MAP
Tue Sep 15 11:08:56 - 5680 - OnUrlMap: storing physical path (c:\inetpub\wwwroot\hp.aspx.net\exec\action\plans\browsemode\details\filter\plnid.27402\hspos\hsnet\page\1\planid\27402), 144 bytes, in ptr (0x000b3828)
Tue Sep 15 11:08:56 - 5680 - HttpFilterProc: SF_NOTIFY_URL_MAP
Tue Sep 15 11:08:56 - 5680 - OnUrlMap: storing physical path (c:\inetpub\wwwroot\hp.aspx.net\exec\action\plans\browsemode\details\filter\plnid.27402\hspos\hsnet\page\1\planid\27402), 144 bytes, in ptr (0x000b3828)
Tue Sep 15 11:08:56 - 5680 - HttpFilterProc: SF_NOTIFY_URL_MAP
Tue Sep 15 11:08:56 - 5680 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Tue Sep 15 11:08:56 - 5680 - DoRewrites
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: getting 'url'
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: 128 bytes
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: result ''
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: getting 'url'
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: 126 bytes ptr:0x0010FFC0
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: 'url' = '/hp.aspx.net/exec/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402'
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: 1 bytes
Tue Sep 15 11:08:56 - 5680 - GetServerVariable_AutoFree: result ''
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: getting 'method'
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: 4 bytes ptr:0x00110158
Tue Sep 15 11:08:56 - 5680 - GetHeader_AutoFree: 'method' = 'GET'
Tue Sep 15 11:08:56 - 5680 - DoRewrites: Url: '/hp.aspx.net/exec/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402'
Tue Sep 15 11:08:56 - 5680 - EvaluateRules: depth=0
Tue Sep 15 11:08:56 - 5680 - EvaluateRules: Rule 1 : 4 matches
Tue Sep 15 11:08:56 - 5680 - ReplaceServerVariables: InputString='/$3?$1=$2' out='/$3?$1=$2'
Tue Sep 15 11:08:56 - 5680 - GenerateReplacementString: src='/hp.aspx.net/exec/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402','(null)' ReplacePattern='/$3?$1=$2' vec=[[ [ 0, 125, 1, 19, 20, 24, 25, 125] [] ] counts=4,0
Tue Sep 15 11:08:56 - 5680 - GenerateReplacementString: replacing ($3) with 'action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402'
Tue Sep 15 11:08:56 - 5680 - GenerateReplacementString: replacing ($1) with 'hp.aspx.net'
Tue Sep 15 11:08:56 - 5680 - GenerateReplacementString: replacing ($2) with 'exec'
Tue Sep 15 11:08:56 - 5680 - ApplyCaseConversion: before '/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec'
Tue Sep 15 11:08:56 - 5680 - ApplyCaseConversion: after '/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec'
Tue Sep 15 11:08:56 - 5680 - GenerateReplacementString: result '/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec'
Tue Sep 15 11:08:56 - 5680 - EvaluateRules: Result (length 125): /action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec
Tue Sep 15 11:08:56 - 5680 - EvaluateRules: Last Rule
Tue Sep 15 11:08:56 - 5680 - EvaluateRules: returning 1
Tue Sep 15 11:08:56 - 5680 - DoRewrites: Rewrite Url to: '/action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec'
Tue Sep 15 11:08:56 - 5680 - HttpFilterProc: SF_NOTIFY_URL_MAP
Tue Sep 15 11:08:56 - 5680 - OnUrlMap: storing physical path (c:\inetpub\wwwroot\action\plans\browsemode\details\filter\plnid.27402\hspos\hsnet\page\1\planid\27402), 120 bytes, in ptr (0x000b3828)

My problem is probably my extra folder "hp.aspx.net", since I'm developing on Windows XP, I have multiple folders under the 1 web site.  It’s also  not substituting default.aspx for exec, it’s just dropping it.

I believe it’s rewriting the url to /action/plans/browsemode/details/filter/plnid.27402/hspos/hsnet/page/1/planid/27402?hp.aspx.net=exec

What I’m looking for would be http://localhost/hp.aspx.net/default.aspx?action=plans&browsemode=details&filter=plnid.27402&hspos=hsnet&page=1&planid=27402

Or http://www.domain.com/default.aspx?action=plans&browsemode=details&filter=plnid.27402&hspos=hsnet&page=1&planid=27402

thanks for your help.



From: [email removed]
To: [email removed]
Date: Tue, 15 Sep 2009 09:00:36 -0700
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

The example you cited comes pretty close to what you want. What problem are you having?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 11:01 AM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

 

From: Cheeso

The example you cited comes pretty close to what you want. What problem are you having?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 15, 2009 at 4:51 PM

I think maybe you should try the TestDriver program.    It will help you figure out which rules are firing, and how.

Also I suggest you start more simply, and then work up to what you want.   Start with one requirement,let's say, a segmented path transformed into URL params.  Get that working, completely.   Then add something, let's say, the requirement that the first path must be hp.aspx.net.  Get that working.  Continue adding one requirement at a time.  Keep it simple. 

You may have to unlock the CHM file in order to read it.

I cannot view the CHM documentation. The error is: "This program cannot display the webpage." or, "The address is invalid." Is there an error with the chm file?
No, there is no problem with the CHM file. You have likely encountered a problem with Windows protection of files downloaded from less trusted locations. To view the chm file, within Windows Explorer, right-click on the CHM file, select properties, and Unblock it (button in lower part of properties window).

 

Sep 15, 2009 at 4:59 PM

That was the issue with the help file, thanks.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 11:52 AM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

I think maybe you should try the TestDriver program. It will help you figure out which rules are firing, and how.

Also I suggest you start more simply, and then work up to what you want. Start with one requirement,let's say, a segmented path transformed into URL params. Get that working, completely. Then add something, let's say, the requirement that the first path must be hp.aspx.net. Get that working. Continue adding one requirement at a time. Keep it simple.

You may have to unlock the CHM file in order to read it.

I cannot view the CHM documentation. The error is: "This program cannot display the webpage." or, "The address is invalid." Is there an error with the chm file?
No, there is no problem with the CHM file. You have likely encountered a problem with Windows protection of files downloaded from less trusted locations. To view the chm file, within Windows Explorer, right-click on the CHM file, select properties, and Unblock it (button in lower part of properties window).

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Sep 15, 2009 at 5:22 PM

This is what I’ve put in a sampleurl.txt file.

/exec

/exec/

/exec/hspos/hsnet

When I run the testdriver, all I get is “no action ‘/exec/’ è --“

Shouldn’t I see the translated url to the right?  Do I need to include the full url?

From: DanPFW [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 12:00 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: DanPFW

That was the issue with the help file, thanks.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 11:52 AM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

I think maybe you should try the TestDriver program. It will help you figure out which rules are firing, and how.

Also I suggest you start more simply, and then work up to what you want. Start with one requirement,let's say, a segmented path transformed into URL params. Get that working, completely. Then add something, let's say, the requirement that the first path must be hp.aspx.net. Get that working. Continue adding one requirement at a time. Keep it simple.

You may have to unlock the CHM file in order to read it.

I cannot view the CHM documentation. The error is: "This program cannot display the webpage." or, "The address is invalid." Is there an error with the chm file?
No, there is no problem with the CHM file. You have likely encountered a problem with Windows protection of files downloaded from less trusted locations. To view the chm file, within Windows Explorer, right-click on the CHM file, select properties, and Unblock it (button in lower part of properties window).

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 15, 2009 at 5:33 PM

You will see the rewritten URL to the right, if the URL is rewritten according to the rewrite rules.

Which rule do you expect to fire on that URL?  If you raise logging to 4 (LogLevel 4), then using the TestDriver, you should see the result of applying each rule to each URL.  The rule you expect to fire, is not firing.  Why?  Then you can focus on that single rule, for that single URL.

No, you on't need the full URL, only the URL path.

 

 

Sep 15, 2009 at 6:31 PM

I’m back to square 1.  Now I’ve noticed I can’t even start a debugging session from Visual Studio.  Dialog msg = “Unable to Start Debugging on the Web Server.” …..

Is this normal?

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 12:37 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

You will see the rewritten URL to the right, if the URL is rewritten according to the rewrite rules.

Which rule do you expect to fire on that URL? If you raise logging to 4 (LogLevel 4), then using the TestDriver, you should see the result of applying each rule to each URL. The rule you expect to fire, is not firing. Why? Then you can focus on that single rule, for that single URL.

No, you on't need the full URL, only the URL path.

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 15, 2009 at 6:43 PM

I don't know about the problem you're having with Visual Studio.  I can't see the image. but anyway, I won't be much help with that.

I thought you were going to run the TestDriver? 

 

Sep 15, 2009 at 6:45 PM

I have been trying testdriver, I still don’t get any results, but I still need to be able to run/debug my site in Visual Studio.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 1:44 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

I don't know about the problem you're having with Visual Studio. I can't see the image. but anyway, I won't be much help with that.

I thought you were going to run the TestDriver?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 15, 2009 at 6:56 PM

What does it mean you "don't get any results" ?  Do you mean, the testdriver does not run at all?   Do you mean, you don't get the results you want?  The purpose of the TestDriver, is to give you some insight into the operation of the rewrite engine, the application of each rule, so that you can adjust the rules to get the results you want. 

If you don't get the results you want, you should still see the logging that tells you which rules are firing and which not. This is what I was talking about earlier.  There is one rule in the set that you expect to fire with a given incoming URL.  The logging tells you whether the rule fires or not, and if it does not, you know that you need to adjust that particular rule.

I'm not going to be able to help you debug your site in Visual Studio.  That seems like a completely separate thing from IIRF, or am I mistaken?

 

Sep 15, 2009 at 7:06 PM

This is what I get back when I run the tool and there is nothing useful in the log, although this rule is probably setup completely wrong.

RewriteRule ^/exec/$    /default.aspx?    [I,L]

RewriteRule ^.*/exec(.*)$           /default.aspx     [I,L]

Processing URLs...(C:\Temp\SampleUrls.txt)

NO ACTION '/localhost/' ==> --

NO ACTION '/exec' ==> --

NO ACTION '/exec/' ==> --

NO ACTION '/exec/hspos/hsnet' ==> --

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 1:57 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

What does it mean you "don't get any results" ? Do you mean, the testdriver does not run at all? Do you mean, you don't get the results you want? The purpose of the TestDriver, is to give you some insight into the operation of the rewrite engine, the application of each rule, so that you can adjust the rules to get the results you want.

If you don't get the results you want, you should still see the logging that tells you which rules are firing and which not. This is what I was talking about earlier. There is one rule in the set that you expect to fire with a given incoming URL. The logging tells you whether the rule fires or not, and if it does not, you know that you need to adjust that particular rule.

I'm not going to be able to help you debug your site in Visual Studio. That seems like a completely separate thing from IIRF, or am I mistaken?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Sep 15, 2009 at 8:15 PM

Can you try to help me with something simple?

I’d like to take any url with a pattern of domain.xxx and do a redirect, attaching www. To the front and retaining the entire querystring.  This is what I’ve got, for some reason, www. Gets appended twice.  If the host name is already xxx.domain.xxx, it should be left alone.

RewriteCond %{HTTP_HOST} ^([^.]+\.(.+)) [I]

RedirectRule (.*) http://www.%1$1 [I,R=301]

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 15, 2009 1:57 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

What does it mean you "don't get any results" ? Do you mean, the testdriver does not run at all? Do you mean, you don't get the results you want? The purpose of the TestDriver, is to give you some insight into the operation of the rewrite engine, the application of each rule, so that you can adjust the rules to get the results you want.

If you don't get the results you want, you should still see the logging that tells you which rules are firing and which not. This is what I was talking about earlier. There is one rule in the set that you expect to fire with a given incoming URL. The logging tells you whether the rule fires or not, and if it does not, you know that you need to adjust that particular rule.

I'm not going to be able to help you debug your site in Visual Studio. That seems like a completely separate thing from IIRF, or am I mistaken?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 15, 2009 at 8:19 PM
Edited Sep 15, 2009 at 8:20 PM

on your first question, When you run the testdriver, it emits the log messages to stdout.  But you need to set the loglevel in the ini file, with (LogLevel 4) for it to emit anything useful.  I am guessing you don't have a LogLevel directive in the ini file, which is why you get so little out of the testdriver. 

on your second, you should exclude hostnames that begin with www, if you don't want to rewrite them.

RewriteCond %{HTTP_HOST} ^(?!www)([^.]+\.(.+)) [I]
RedirectRule (.*) http://www.%1$1 [I,R=301]
Sep 15, 2009 at 8:26 PM
thanks, that seems to work, just not sure why, since i had mymachine.com in my hosts file and that's what I was typing as an address.


From: [email removed]
To: [email removed]
Date: Tue, 15 Sep 2009 13:19:21 -0700
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso
on your first question, When you run the testdriver, it emits the log messages to stdout. But you need to set the loglevel in the ini file, with (LogLevel 4) for it to emit anything useful.
on your second, you should exclude hostnames that begin with www, if you don't want to rewrite them.
RewriteCond %{HTTP_HOST} ^(?!www)([^.]+\.(.+)) [I]
RedirectRule (.*) http://www.%1$1 [I,R=301]
Coordinator
Sep 15, 2009 at 8:29 PM
Edited Sep 15, 2009 at 8:46 PM

I've no idea what your last response means.

The RewriteCond works because it filters out www from the hosts that would be rewritten.  The (?!www) does this.   There are examples that cover this in the doc.

 

Sep 21, 2009 at 7:27 PM

could you please tell me what I'm doing wrong.

I'm trying to get the rewriter working in development and production with the same statements.  My url in development is localhost/folder/default.aspx, in production, it's domain.com/default.aspx.

I've got 1 rewrite working I believe.

any url that comes into www.domain.com/rdr/1234 rewrites to the following and appears to work.

RewriteRule ^(.*)/rdr/?(.*)$ $1/shurl/ShortURLRedirect.aspx?redir=$2 [I,L]

 

I tried modifying the TransformUrlSegmentsToQueryParamsIteratively2 sample, but can't seem to get it to work correctly.

 

First, I check for default.aspx or exec in it's place and rewrite so it's always default.aspx.

RewriteRule ^(.*?)/(default.aspx|exec)/?(.*)$ $1/default.aspx/$3 [I]

 

I then try to parse the querystring with the modified sample code.

# handle case with no query string .  This rule fires the first time through.
#RewriteRule ^(.*)/(?=default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)$ $1/$4?$2=$3 [I]

# handle case with existing query string. This rule fires potentially multiple times.
#RewriteRule ^(.*)/(?=default\.aspx)([^\?\/]+)/([^\?\/]+)/([^\?]+)\?(.+)$ $1/$4?$5&$2=$3 [I]


# Handle the case with one more pair of segments. This fires once (last).
# It fires when there is an even number of segments.
#RewriteRule ^(.*)/(?=default\.aspx)([^\?\/]+)/([^\?\/]+)\?([^\?]+)$ /$1/default.aspx?$4&$2=$3 [I,L]

# Handle the case with exactly one pair of segments. This fires once (last).
#RewriteRule ^(.*)/(?=default\.aspx)([^\?\/]+)/([^\?\/]+)$ /$1/default.aspx?$2=$3 [I,L]

 

Coordinator
Sep 21, 2009 at 8:41 PM

I'm going to ask some dumb questions, be patient with me.

danpfw wrote:

First, I check for default.aspx or exec in it's place and rewrite so it's always default.aspx.

RewriteRule ^(.*?)/(default.aspx|exec)/?(.*)$ $1/default.aspx/$3 [I]

What is meant by the leading (.*?) / Why is that part there? Does it capture any URL path up to but not including the "default.aspx" or the "exec"? Are you happy with this rule and how it works?

danpfw wrote:

I then try to parse the querystring with the modified sample code.

The rest of the rules are commented out. Not sure if that is what you intend.

If the rules were not been commented out, then there are some simplifications you could make.  You have a segment in each regex that reads (?=default\.aspx). This is a non-capturing lookahead if I am not mistaken, and in english it means "the next thing is default.aspx, but don't capture it". You then follow that segment with a capturing group, which captures any sequence of characters that is neither a question mark or a slash. ([^\?\/]+). In most cases I am guessing that group will capture "default.aspx" because you have the preceding non=capturing group that matches only when the string is default.aspxx. Is this making sense?

if that's the case then you can replace (?=default.aspx)([^\?\/]+)/ with the simpler "default\.aspx/" . Why go through all the extra complication?

I was going to explain each of the segments in each of the regex patterns you have, but given what I just went through with that one, I'm not sure that's helpful.  It may be better to understand what you want to do, in English, instead.   Rather than starting with the rules you are using (here are my rules, why don't they work?), why not start by explaining what it is that you want to do.  Example:  "rewrite incoming urls like '/exec' to '/default.aspx' "

And, It might be better to start very simply, and work up from there. For example, I think you want to rewrite incoming urls like "/exec" to "default.aspx". If you've got that working, we can go to the next step up in complexity, whatever it is.  Let's not try to solve everything all at once.

You'll have to be really clear and basic in your explanations of what you want.  Remember I am not looking at your screen and I know nothing about your environment except what you tell me here, and I probably don't remember what you told me 5 days ago.  It might be best to imagine that this is the first time I am seeing your situation.

 

Sep 22, 2009 at 1:58 PM

(.*?) / is capturing the folder name that is used on my development machine.  Windows XP (IIS 5.1) doesn’t support multiple sites, so sites need to be in sub folders.  This appears to be working so far.

The person who originally setup my site substituted “exec” for a page name, so yes, I want to translate exec to default.aspx.  That is the only page that is called today.  All parameters after the “exec” are paired, hence I was trying to use your TransformUrlSegmentsToQueryParamsIteratively2 sample.

I commented the rules out, since they weren’t working anyway.

If I can get these working, the next step I’d like to take is to create new url’s that don’t require the exec or default.aspx in the path.

I spent the last half of last week, trying to learn as much as I could about mod_rewrite.  I’ve got a little better handle on it now, but still a long way to go.

Thanks for your help.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Monday, September 21, 2009 3:43 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

I'm going to ask some dumb questions, be patient with me.

danpfw wrote:

First, I check for default.aspx or exec in it's place and rewrite so it's always default.aspx.

RewriteRule ^(.*?)/(default.aspx|exec)/?(.*)$ $1/default.aspx/$3 [I]

What is meant by the leading (.*?) / Why is that part there? Does it capture any URL path up to but not including the "default.aspx" or the "exec"? Are you happy with this rule and how it works?

danpfw wrote:

I then try to parse the querystring with the modified sample code.

The rest of the rules are commented out. Not sure if that is what you intend.

If the rules were not been commented out, then there are some simplifications you could make. You have a segment in each regex that reads (?=default\.aspx). This is a non-capturing lookahead if I am not mistaken, and in english it means "the next thing is default.aspx, but don't capture it". You then follow that segment with a capturing group, which captures any sequence of characters that is neither a question mark or a slash. ([^\?\/]+). In most cases I am guessing that group will capture "default.aspx" because you have the preceding non=capturing group that matches only when the string is default.aspxx. Is this making sense?

if that's the case then you can replace (?=default.aspx)([^\?\/]+)/ with the simpler "default\.aspx/" . Why go through all the extra complication?

I was going to explain each of the segments in each of the regex patterns you have, but given what I just went through with that one, I'm not sure that's helpful. It may be better to understand what you want to do, in English, instead. Rather than starting with the rules you are using (here are my rules, why don't they work?), why not start by explaining what it is that you want to do. Example: "rewrite incoming urls like '/exec' to '/default.aspx' "

And, It might be better to start very simply, and work up from there. For example, I think you want to rewrite incoming urls like "/exec" to "default.aspx". If you've got that working, we can go to the next step up in complexity, whatever it is. Let's not try to solve everything all at once.

You'll have to be really clear and basic in your explanations of what you want. Remember I am not looking at your screen and I know nothing about your environment except what you tell me here, and I probably don't remember what you told me 5 days ago. It might be best to imagine that this is the first time I am seeing your situation.

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 22, 2009 at 3:17 PM

yeah, so if you have another set of URLs that you want to rewrite, and you want some help with the rewriterule, you have to describe what it is you want to me, following the example I gave.   "Rewrite incoming URLS like /exec?foo=bar&gee=7 to /default.aspx/foo/bar/gee/7"   if that is what you want.   Or it could be you want to go the opposite direction:  "Rewrite incoming URLS like /exec/foo/bar/gee/7 to /default.aspx?foo=bar&gee=7"  Or it could be something different. 

if you can describe it, with examples, I can help write a rule.

 

Sep 22, 2009 at 3:20 PM

Sorry, /exec/foo/bar/gee/7 to /default.aspx?foo=bar&gee=7 is what I’m trying to accomplish.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 22, 2009 10:18 AM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

yeah, so if you have another set of URLs that you want to rewrite, and you want some help with the rewriterule, you have to describe what it is you want to me, following the example I gave. "Rewrite incoming URLS like /exec?foo=bar&gee=7 to /default.aspx/foo/bar/gee/7" if that is what you want. Or it could be you want to go the opposite direction: "Rewrite incoming URLS like /exec/foo/bar/gee/7 to /default.aspx?foo=bar&gee=7" Or it could be something different.

if you can describe it, with examples, I can help write a rule.

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 22, 2009 at 4:52 PM

My vdir is named "winisp" in this case.  Replace that with your vdir, or, if it is the default, just remove all "/winisp" .

# Iirf.ini
#
# site or app-specific ini file
#

RewriteEngine ON
RewriteLog  c:\temp\iirf-v2.0.winisp
RewriteLogLevel 3

StatusUrl  /iirfStatus

CondSubstringBackrefFlag *
MaxMatchCount 10


# -------------------------------------------------------

# DON'T rewrite default.aspx. Just in case. 
RewriteRule ^/winisp/default\.aspx/?  -   [L]

# Handle the case with no query string.  This rule fires the first time through.
RewriteRule ^/winisp/exec/([^\?\/]+)/([^\?\/]+)(/([^\?]+))?$             /winisp/exec$3?$1=$2

# Handle the case with existing query string. This rule fires potentially multiple times,
# each time, transforming a pair of path segments to a p=v segment in the query string. 
RewriteRule ^/winisp/exec/([^\?\/]+)/([^\?\/]+)(/([^\?]+))?\?(.+)$       /winisp/exec$3?$5&$1=$2


# Handle the case where there is an odd number of segments: an invalid input URL.
# This fires once, after one or more pairs of path segments have been parsed.  
# This should be redirected to a 404 page 
RewriteRule ^/winisp/exec/([^\/\?]+)\?([^\?]+)$ /winisp/default.aspx?Error&flavor=OddNumberOfSegments  [L]

# Handle the edge case where there is only one segment. 
# This should be redirected to a 404 page. 
RewriteRule ^/winisp/exec/([^\/\?]+)$           /winisp/default.aspx?Error&flavor=FoundOnlyOneSegment  [L]


# Translate exec to default.aspx. This fires once (last).
RewriteRule ^/winisp/exec(.*)                   /winisp/default.aspx$1                                 [L]


# Any URL that falls through to this rule is an error.
# This should be redirected to a 404 page. 
RewriteRule  ^.*$                               /winisp/default.aspx?Error&flavor=BadForm              [L]

Sep 22, 2009 at 6:54 PM

No luck, I’ve tried registering  IonicIsapiRewriter-2.0-bin\bin\IIRF.dll as the isapi filter and it crashes IIS 5.1 on Windows XP.

These rules don’t work with 1.2.16, all requests just end up at the error page.  I added the [I] flag to ignore case.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 22, 2009 11:53 AM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

My vdir is named "winisp" in this case. Replace that with your vdir, or, if it is the default, just remove all "/winisp" .

# Iirf.ini
#
# site or app-specific ini file
#
 
RewriteEngine ON
RewriteLog  c:\temp\iirf-v2.0.winisp
RewriteLogLevel 3
 
StatusUrl  /iirfStatus
 
CondSubstringBackrefFlag *
MaxMatchCount 10
 
 
# -------------------------------------------------------
 
# DON'T rewrite default.aspx. Just in case. 
RewriteRule ^/winisp/default\.aspx/?  -   [L]
 
# Handle the case with no query string.  This rule fires the first time through.
RewriteRule ^/winisp/exec/([^\?\/]+)/([^\?\/]+)(/([^\?]+))?$             /winisp/exec$3?$1=$2
 
# Handle the case with existing query string. This rule fires potentially multiple times,
# each time, transforming a pair of path segments to a p=v segment in the query string. 
RewriteRule ^/winisp/exec/([^\?\/]+)/([^\?\/]+)(/([^\?]+))?\?(.+)$       /winisp/exec$3?$5&$1=$2
 
 
# Handle the case where there is an odd number of segments: an invalid input URL.
# This fires once, after one or more pairs of path segments have been parsed.  
# This should be redirected to a 404 page 
RewriteRule ^/winisp/exec/([^\/\?]+)\?([^\?]+)$ /winisp/default.aspx?Error&flavor=OddNumberOfSegments  [L]
 
# Handle the edge case where there is only one segment. 
# This should be redirected to a 404 page. 
RewriteRule ^/winisp/exec/([^\/\?]+)$           /winisp/default.aspx?Error&flavor=FoundOnlyOneSegment  [L]
 
 
# Translate exec to default.aspx. This fires once (last).
RewriteRule ^/winisp/exec(.*)                   /winisp/default.aspx$1                                 [L]
 
 
# Any URL that falls through to this rule is an error.
# This should be redirected to a 404 page. 
RewriteRule  ^.*$                               /winisp/default.aspx?Error&flavor=BadForm              [L]

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 22, 2009 at 9:19 PM

hmm, well.

if I knew what URLs you passed in, and what result you got out, I might be able to help you figure out why the rules don't work on v1.2. This is all in the logfile.

The crash of v2.0 - is that new?  Did you not have it working before? Did you troubleshoot it as it's described in the doc?  did you look in the event log for the explanation? 

 

Sep 23, 2009 at 7:55 PM

The visual studio debugger starts with an unhandled win32 exception in inetinfo.exe and I try to open http://localhost/iirfstatus.

The rules doesn’t seem to work with default.aspx.  I’m still testing the rest.

From: Cheeso [mailto:notifications@codeplex.com]
Sent: Tuesday, September 22, 2009 4:20 PM
To: danpfw@hotmail.com
Subject: Re: help with rewrites [IIRF:68991]

From: Cheeso

hmm, well.

if I knew what URLs you passed in, and what result you got out, I might be able to help you figure out why the rules don't work on v1.2. This is all in the logfile.

The crash of v2.0 - is that new? Did you not have it working before? Did you troubleshoot it as it's described in the doc? did you look in the event log for the explanation?

Read the full discussion online.

To add a post to this discussion, reply to this email (IIRF@discussions.codeplex.com)

To start a new discussion for this project, email IIRF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Sep 24, 2009 at 6:34 PM

regarding the crash of v2.0 DLL, I think you are missing the IirfGlobal.ini file.

The filter shouldn't crash in this case, but it does. To avoid the crash, provide that ini file.  In the meantime I will fix that bug.

Coordinator
Sep 24, 2009 at 8:36 PM

ok, v2.0n, which is available now, will gracefully handle the case where no ini file is found.

you should be able to run that updated v2.0 IIRF.dll.

That doesn't solve your other problem, which is why your rules don't work the way you think they ought to.

For that you need to look into the IIRF log.