Redirect using Map and Querystring
3 posts
• Page 1 of 1
Redirect using Map and Querystring
Hi there,
I am using build 100 on Windows 2003 IIS6.
I am using a dbd map to lookup a parameter from a querystring.
This is my rule:
DBDPrepareSQL "select redirect, item from vwBargainsRedirect where item =@KEY" bargainsRedirect_map_select
RewriteMap bargainsRedirect_map_dbd dbd:bargainsRedirect_map_select
RewriteCond %{QUERY_STRING} ^ref=(.*)$
RewriteRule bargains/view.asp ${bargainsRedirect_map_dbd:%1}? [NC,L,R=301]
The sql data has 2 columns, item and redirect:
item: XXYAM3000A-40
redirect: /audio/used/mixers/analogue_mixers_185/XXYAM3000A-40.asp
This fails (actually redirects to root of site):
http://www.example.com/audio/bargains/view.asp?ref=XXYAM3000A-40&cat1=Audio
This works:
http://www.example.com/audio/bargains/view.asp?ref=XXYAM3000A-40
It redirects to:
http://www.example.com/audio/used/mixers/analogue_mixers_185/XXYAM3000A-40.asp
What do I need to change in my rule?
Cheers,
Steve
I am using build 100 on Windows 2003 IIS6.
I am using a dbd map to lookup a parameter from a querystring.
This is my rule:
DBDPrepareSQL "select redirect, item from vwBargainsRedirect where item =@KEY" bargainsRedirect_map_select
RewriteMap bargainsRedirect_map_dbd dbd:bargainsRedirect_map_select
RewriteCond %{QUERY_STRING} ^ref=(.*)$
RewriteRule bargains/view.asp ${bargainsRedirect_map_dbd:%1}? [NC,L,R=301]
The sql data has 2 columns, item and redirect:
item: XXYAM3000A-40
redirect: /audio/used/mixers/analogue_mixers_185/XXYAM3000A-40.asp
This fails (actually redirects to root of site):
http://www.example.com/audio/bargains/view.asp?ref=XXYAM3000A-40&cat1=Audio
This works:
http://www.example.com/audio/bargains/view.asp?ref=XXYAM3000A-40
It redirects to:
http://www.example.com/audio/used/mixers/analogue_mixers_185/XXYAM3000A-40.asp
What do I need to change in my rule?
Cheers,
Steve
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Redirect using Map and Querystring
Hello,
Here's the thing:
In this condition having '$' at the end defines that this is the end of the pattern. So in case you request "?ref=XXYAM3000A-40&cat1=Audio" you get "XXYAM3000A-40&cat1=Audio" matched as a value inside (.*) - that's why it doesn't work. What you need to do is to replace this condition with the following:
We also eliminate the '$' so that your querystring parameter may be followed by other parameter.
regards
Andrew
Here's the thing:
- Code: Select all
RewriteCond %{QUERY_STRING} ^ref=(.*)$
In this condition having '$' at the end defines that this is the end of the pattern. So in case you request "?ref=XXYAM3000A-40&cat1=Audio" you get "XXYAM3000A-40&cat1=Audio" matched as a value inside (.*) - that's why it doesn't work. What you need to do is to replace this condition with the following:
- Code: Select all
RewriteCond %{QUERY_STRING} ^ref=([^&]+)
We also eliminate the '$' so that your querystring parameter may be followed by other parameter.
regards
Andrew
Re: Redirect using Map and Querystring
Hi Andrew,
That works, thank you. Brilliant product, excellent support, but funny syntax, one day I will get my head around it all
Cheers,
Steve
That works, thank you. Brilliant product, excellent support, but funny syntax, one day I will get my head around it all
Cheers,
Steve
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 18 guests