Chaining?
5 posts
• Page 1 of 1
- ThomasAlbrighton
- Posts: 7
- Joined: 30 Jan 2013, 00:02
Chaining?
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
Thanks,
Thomas Albrighton
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
Re: Chaining?
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.
Could you explain what are the rules you wrote supposed to do. Describe the scenario and I'll optimize them as much as possible.
- ThomasAlbrighton
- Posts: 7
- Joined: 30 Jan 2013, 00:02
Re: Chaining?
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
- ThomasAlbrighton
- Posts: 7
- Joined: 30 Jan 2013, 00:02
Re: Chaining?
sorry that was old code.
It has changed to
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]
Re: Chaining?
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})
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})
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests