Rewrite a rewrite?

Topics: User Forum
Aug 27, 2009 at 7:02 AM

Hi again :) I've got a rule that rewrites any calls to /assets/xxxx (where 'xxxx' is the asset type, like Cars, Trucks, Buses etc.) to a script that takes the asset name and does a lookup for the ID of that specific asset type and then does a response.redirect to /search/newsearch.asp?catid=n (where 'n' is the asset type ID. The rule looks like this:

RewriteRule /assets/(.*)$    /search/Switcher.asp?A=$1

This part works perfectly. However, I would like to be able to rewrite the resulting redirect so that the browser address bar shows rather than To that end I created another rule to try and achieve this (this second rule is not yet working):

RewriteRule /Search/NewSearch.asp?cat_id=.*$    /assets/Cars

And I'd also like to avoid having to run another script to do the reverse lookup of the name from the ID again, because it seems like then I'll be stuck in an infinite loop of forward and reverse lookups.

My question is therefore this: is there a way for me to "save" the initial backreference from my first rule match, and use it in my second rule match so that I can use it to rewrite the redirect rule? Will IIRF even rewrite a redirect prior to it being served? I'd just like to know if I'm barking up the wrong tree so as not to spend too much time on this.

Thanks in advance!

Aug 27, 2009 at 8:27 AM

I'm not clear on what you are doing.

In similar cases, people have embed the mapping between "assets" and "ids" in the IIRF file itself.  For example

  RewriteRule ^/assets/Cars$      /search/Whatever.asp?cat_id=7 [L]
  RewriteRule ^/assets/Trucks$    /search/Whatever.asp?cat_id=8 [L]
  RewriteRule ^/assets/Trains$    /search/Whatever.asp?cat_id=3 [L]

This would eliminate the Switcher.asp script, I think.  The intelligence you have in the switcher now, will instead just be in an ini file.  This should work unless the map is really large, extremely large, or unless it changes often.  If the mapping is stored in a database, let's say there are 250 rows... I could imagine even automatically generating the ini file.

There is no way to preserve a capture across requests in IIRF. Each request is processed separately.