Redirect using Map and Querystring

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 34
Joined: 19 Feb 2013, 11:44

Redirect using Map and Querystring

01 Mar 2013, 07:48

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

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Redirect using Map and Querystring

01 Mar 2013, 11:28

Hello,

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

User avatar
Posts: 34
Joined: 19 Feb 2013, 11:44

Re: Redirect using Map and Querystring

01 Mar 2013, 11:46

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

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 18 guests