Chaining?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 7
Joined: 30 Jan 2013, 00:02

Chaining?

04 Feb 2013, 01:57

Hey guys,
I was looking at the documentation and I saw the chain flag [C] but couldn't find any good examples.
I was just wondering if something like this would work instead of making a rule for every variation of query strings

Code: Select all
RewriteRule residential\.asp$ residential/ [NC,C]

RewriteCond %{QUERY_STRING} serviceid=([^&]*)[NC]
RewriteRule residential/$ residential/${serviceid:%1}/ [NC,C]

RewriteCond %{QUERY_STRING} stateid=([^&]*)[NC]
RewriteRule residential/.*/$ residential/.*/${state:%1}/ [NC,C]

RewriteCond %{QUERY_STRING} suburb=([^&]*)[NC]
RewriteRule residential/.*/$ residential/.*/%1}/ [NC,R=302,L]


Thanks,
Thomas Albrighton

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Chaining?

04 Feb 2013, 07:16

Hello, Thomas

Could you explain what are the rules you wrote supposed to do. Describe the scenario and I'll optimize them as much as possible.

User avatar
Posts: 7
Joined: 30 Jan 2013, 00:02

Re: Chaining?

04 Feb 2013, 19:47

ThomasAlbrighton wrote:
Code: Select all
RewriteRule residential\.asp$ residential/ [NC,C]

RewriteCond %{QUERY_STRING} serviceid=([^&]*)[NC]
RewriteRule residential/$ residential/${serviceid:%1}/ [NC,C]

RewriteCond %{QUERY_STRING} stateid=([^&]*)[NC]
RewriteRule residential/.*/$ residential/.*/${state:%1}/ [NC,C]

RewriteCond %{QUERY_STRING} suburb=([^&]*)[NC]
RewriteRule residential/.*/$ residential/.*/%1}/ [NC,R=302,L]



Hey,
I have a URL with a bunch of optional query strings.
eg ?a=A&c=C or ?c=C&d=D or ?b=B&d=D or ?a=A&b=B&c=C&d=D etc

Instead of writing rewrite rules for every scenario I'm trying to get something like the above code to work where it checks for "a=A" then checks for "b=B" separately and so on.

Thank-you
Thomas Albrighton

User avatar
Posts: 7
Joined: 30 Jan 2013, 00:02

Re: Chaining?

04 Feb 2013, 20:31

sorry that was old code.
It has changed to
Code: Select all
RewriteCond %{QUERY_STRING} .*serviceid=([^&]*).* [NC]
RewriteRule residential\.asp$ residential/${serviceid:%1}/ [NC]
               
RewriteCond %{QUERY_STRING} .*stateid=([^&]*).* [NC]
RewriteRule residential/(.*)/$ residential/$1/${state:%1}/ [NC]
               
RewriteCond %{QUERY_STRING} .*suburb=([^&]*).* [NC]
RewriteRule residential/([^/]*)/([^/]*)/$ residential/$1/$2/%1/? [NC,R=302]
               
RewriteRule residential/([^/]*)/([^/]*)/([^/]*)/ residential.asp?serviceid=${serviceidRev:$1}&stateid=${stateRev:$2}&suburb=$3 [NC,L]

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Chaining?

05 Feb 2013, 08:50

Hello,

please consider using the following condition to account for all possible combinations of 4 parameters (a,b,c,d):

RewriteCond %{QUERY_STRING} (?:a=([^&]*))?(?:.*b=([^&]*))?(?:.*c=([^&]*))?(?:.*d=([^&]*))? [NC]

You can check if particular parameter exists like this: ?%1 and then put e.g. ${serviceid:%1}

So, together the use of parameter "a" may look like:

(?%1${serviceid:%1})

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests