RewriteMap help needed

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 12
Joined: 21 Feb 2013, 22:15

RewriteMap help needed

17 Apr 2013, 12:47

Hello all

Hope someone can help with a map file issue.
I'm trying to redirect from one url (including query string) to another place.

example of mapfile:

Code: Select all
Product.aspx?abc=&Code=efgh   test.cfm/abc/defghi/jklmnl/1234


example of rule:
Code: Select all
RewriteMap mapfilemn txt:d:\ISAPI_Rewrite3\myfile.txt [NC]
RewriteCond %{HTTP:HOST} .*hostname.co.uk
RewriteCond ${mapfilemn:$1?%{QUERY_STRING}|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://www.hostname.co.uk/${mapfilemn:$1} [NC,R=301,L]


The issue seems to be the query string part.

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

Re: RewriteMap help needed

18 Apr 2013, 00:18

Hello,

Lets try to taylor this in a different way:

Code: Select all
RewriteMap mapfilemn txt:d:\ISAPI_Rewrite3\myfile.txt [NC]

RewriteCond %{HTTP:HOST} .*hostname\.co\.uk
RewriteCond %{REQUEST_URI} ^/(.*) [NC]
RewriteCond ${mapfilemn:%1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://www.hostname.co.uk/${mapfilemn:$1} [NC,R=301,L]


REQUEST_URI matches both the body and the querystring. So I suggest in your mapfile you have:

Product.aspx?abc=&Code=efgh test.cfm/abc/defghi/jklmnl/1234


Regards
Andrew

User avatar
Posts: 12
Joined: 21 Feb 2013, 22:15

Re: RewriteMap help needed

18 Apr 2013, 01:06

Thanks for replying.

Unfortunatley I had already tried what you suggested. All it returns is a 404... its the query string part that seems to be the issue :-(

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

Re: RewriteMap help needed

18 Apr 2013, 02:52

What makes you think so? Please, provide rewrite.log for a testing request.

User avatar
Posts: 12
Joined: 21 Feb 2013, 22:15

Re: RewriteMap help needed

18 Apr 2013, 03:12

Unfortunately i cannot provide the log file as it is so long as we have over 20 websites.

However I tested it by removing the query part (anything after ?) in the mapfile and it redirected ok.
As soon as i put the query string back, it doesn't work.

So it looks like it isn't matching.

User avatar
Posts: 12
Joined: 21 Feb 2013, 22:15

Re: RewriteMap help needed

18 Apr 2013, 12:35

Okay... I've set up a test environment so that I can paste the log file.

Here is the rewrite code config

Code: Select all
RewriteMap mapfilemn txt:c:\ISAPI_Rewrite3\myfile.txt [NC]
RewriteCond %{HTTP:HOST} .*127.0.0.1
RewriteCond %{REQUEST_URI} ^/(.*) [NC]
RewriteCond ${mapfilemn:%1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://127.0.0.1/${mapfilemn:$1} [NC,R=301,L]


and here is the resulting log file contents:

Code: Select all
127.0.0.1 127.0.0.1 (2) init rewrite engine with requested uri /Product.aspx?5kg_Matrix_Anabolic_Protein=&Code=MA11
127.0.0.1 127.0.0.1 (1) Htaccess process request C:\ISAPI_Rewrite3\httpd.conf
127.0.0.1 127.0.0.1 (3) applying pattern '(.*)' to uri '/Product.aspx'
127.0.0.1 127.0.0.1 (4) RewriteCond: input='127.0.0.1' pattern='.*127.0.0.1' => matched
127.0.0.1 127.0.0.1 (4) RewriteCond: input='/Product.aspx' pattern='^/(.*)' => matched
127.0.0.1 127.0.0.1 (5) map lookup FAILED: map=mapfilemn[txt] key=Product.aspx
127.0.0.1 127.0.0.1 (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched


It looks like {REQUEST_URI} doesn't contain the query string part ?!?!?!?

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

Re: RewriteMap help needed

18 Apr 2013, 14:17

Looks like it. Strange. Okay... lets try:

Code: Select all
RewriteMap mapfilemn txt:c:\ISAPI_Rewrite3\myfile.txt [NC]
RewriteCond %{HTTP:HOST} .*127.0.0.1
RewriteCond %{REQUEST_URI} ^/(.*) [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteCond ${mapfilemn:%1\?%2|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://127.0.0.1/${mapfilemn:$1\?%2} [NC,R=301,L]


What will the log show for this rule?

User avatar
Posts: 12
Joined: 21 Feb 2013, 22:15

Re: RewriteMap help needed

18 Apr 2013, 15:39

thanks... looking a bit better but still issue:

the log file is this:

Code: Select all
127.0.0.1 127.0.0.1   (2) init rewrite engine with requested uri /?5kg_Matrix_Anabolic_Protein=&Code=MA11
127.0.0.1 127.0.0.1   (1) Htaccess process request C:\ISAPI_Rewrite3\httpd.conf
127.0.0.1 127.0.0.1   (3) applying pattern '(.*)' to uri '/'
127.0.0.1 127.0.0.1   (4) RewriteCond: input='127.0.0.1' pattern='.*127.0.0.1' => matched
127.0.0.1 127.0.0.1   (4) RewriteCond: input='/' pattern='^/(.*)' => matched
127.0.0.1 127.0.0.1   (4) RewriteCond: input='5kg_Matrix_Anabolic_Protein=&Code=MA11' pattern='(.*)' => matched
127.0.0.1 127.0.0.1   (5) map lookup FAILED: map=mapfilemn[txt] key=?5kg_Matrix_Anabolic_Protein=&Code=MA11
127.0.0.1 127.0.0.1   (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched
127.0.0.1 127.0.0.1   (2) init rewrite engine with requested uri /welcome.png
127.0.0.1 127.0.0.1   (1) Htaccess process request C:\ISAPI_Rewrite3\httpd.conf
127.0.0.1 127.0.0.1   (3) applying pattern '(.*)' to uri '/welcome.png'
127.0.0.1 127.0.0.1   (4) RewriteCond: input='127.0.0.1' pattern='.*127.0.0.1' => matched
127.0.0.1 127.0.0.1   (4) RewriteCond: input='/welcome.png' pattern='^/(.*)' => matched
127.0.0.1 127.0.0.1   (4) RewriteCond: input='' pattern='(.*)' => matched
127.0.0.1 127.0.0.1   (5) map lookup FAILED: map=mapfilemn[txt] key=welcome.png?
127.0.0.1 127.0.0.1   (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched

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

Re: RewriteMap help needed

18 Apr 2013, 17:04

Well, you requested "/?5kg_Matrix_Anabolic_Protein=&Code=MA11", ISAPI_Rewrite looked for "?5kg_Matrix_Anabolic_Protein=&Code=MA11". Didn't find it in a mapfile.
What entry did you have in mapfile?

Rgards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 22 guests