301 mapfile help needed

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

301 mapfile help needed

21 Feb 2013, 22:30

Trying to get my head around this and searched for ages to find solution, i'm sure its not this difficult :-)

Basically i have a simple mapfile, example:

Code: Select all
domain.com/xxxx/yyyy  /shop.asp/somewhere/12345
domain.com/xxxx/zzzz   /shop.asp/somewhere/12345678
domain.com/zzzz           /shop.asp/somewhere2/12345678



All i want to happen is that the rewrite rule looks up the mapfile and does a 301 redirect.
Also, the domain could contain www so the rule should still apply.
In fact the domain.com won't change.

I've tried the following to no avail, making sure http://domain.com is removed so it matches the xxx/yyyy:

Code: Select all
RewriteMap mapfile txt:d:\xyz\map.txt
RewriteRule .*domain.com/(.*) http://www.domain.com/${mapfile:$1} [L,R=301]


This didn't seem to do anything.

then I tried this, keeping the domain.com part in the map file:

Code: Select all
RewriteMap mapfile txt:d:\xyz\map.txt
RewriteRule /(.*) http://www.domain.com/${mapfile:$1} [R=301,L]


This got stuck in a loop and didn't work.

Can anyone help.

much appreciated

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

Re: 301 mapfile help needed

22 Feb 2013, 01:25

You got really close to the problem.
All you need is a condition that checks if the request matches the mapfile:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteMap mapfile txt:d:\xyz\map.txt

RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://www.domain.com/${mapfile:$1} [NC,R=301,L]


Regards
Andrew

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

Re: 301 mapfile help needed

22 Feb 2013, 06:33

Many thanks for the reply.

How silly of me..... it was late (midnight) and totally missed the condition needed.

All working now :-)

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

Re: 301 mapfile help needed

22 Feb 2013, 07:47

Hi

One other question if you can help.

I have another mapfile which is similar to the previous one, the difference is that the second parameter is a domain name.

so for example if the incoming request is
Code: Select all
www.domain1.com/xyz/zzz

I need it to redirect to:
Code: Select all
www.domain2.com


without the query string... just to the root

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

Re: 301 mapfile help needed

22 Feb 2013, 11:39

hello,

the rule would look like(i made it strictly for two-level URLs, as you described):

Code: Select all
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ([^/]+/[^/]+) http://${mapfile:$1}? [NC,R=301,L]



and in your mapfile you'll have entries as in the following:

Code: Select all
aaa/bbbb www.domain2.com
ccc/ddd www.otherdomain.com


Regards
Andrew

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

Re: 301 mapfile help needed

22 Feb 2013, 14:04

Thanks again for the info.

I managed to find solution by trial and error :-)

It seems I had forgotten to prepend with http://

I was getting the redirect added to the end of the initial url, but once i added in the http:// all worked fine.

thanks for your help its much appreciated.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 7 guests