Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 3.0 support forum
 Helicon Tech : ISAPI_Rewrite 3.0 support forum
Subject Topic: MapFile that covers multiple destinations Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
jakob
Newbie
Newbie


Joined: 16 October 2006
Online Status: Offline
Posts: 14
Posted: 17 July 2008 at 4:49am | IP Logged Quote jakob

So I have a mapfile

onepage 4
otherpage 5

and the rules to go with it:
RewriteMap mapfile txt:mapfile.txt
RewriteMap lower int:tolower
RewriteRule ^([^/]+)/?$ /page.asp?id=${mapfile:${lower:$1}}

So www.example.com/onepage rewrites to www.example.com/page.asp?id=4

But what if want some of the pages to be 301 redirects instead? and what if I want www.example.com/thirdpage to point to www.example.com/folder/contact.html that is in a whole other scheme?

thirdpage and fourthpage has no distinct style that can be filtered out by a specific rule...

What can I do? I was kinda thinking about "conditional format patterns ?Ntrue_string:false_string" or the regex conditional asserstions ?() and ?()|

So if i put:

thirdpage /folder/contact.html

in my httpd.conf, then I could make the RewriteRule do something different?

OR if I could have 2 mapfiles, and have the first rule ONLY execute if something is actually found in the mapfile.. is that possible?


Edited by jakob - 17 July 2008 at 5:17am
Back to Top View jakob's Profile Search for other posts by jakob
 
Vyacheslav
Moderator Group
Moderator Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 396
Posted: 17 July 2008 at 5:36am | IP Logged Quote Vyacheslav

Hi jakob1

You can try the following solution:
Code:
RewriteMap map txt:map.txt
RewriteMap lower int:tolower
                 
RewriteRule ^(page_with_redirect1)/?$ index.asp?id=${map:${lower:$1}} [NC,R=301,L]
RewriteRule ^(page_with_redirect2)/?$ index.asp?id=${map:${lower:$1}} [NC,R=301,L]

RewriteRule ^index\.asp$ - [L]
RewriteRule ^([^/]+)/?$ index.asp?id=${map:${lower:$1}}


__________________
Kind regards!
Vyacheslav.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 
jakob
Newbie
Newbie


Joined: 16 October 2006
Online Status: Offline
Posts: 14
Posted: 17 July 2008 at 6:14am | IP Logged Quote jakob

Hello Vyacheslav,

That totally didn't make sense... Can I have 4 RewriteRule's to the same RewriteMap ?

How do I know which one corresponds to which in the mapfile ?

As I read your code it seems I have to write a RewriteRule for each page_with_redirect i have... but I have hundreds.

Could you please clarify your example and show how the mapfile would look?
Back to Top View jakob's Profile Search for other posts by jakob
 
jakob
Newbie
Newbie


Joined: 16 October 2006
Online Status: Offline
Posts: 14
Posted: 17 July 2008 at 6:57am | IP Logged Quote jakob

I just read the docs for RewriteCond at http://www.helicontech.com/isapi_rewrite/doc/RewriteCond.htm

RewriteMap expansions using syntax ${mapname:key|default}.

Do you have any examples on how to use that? Can I set a default for my mapfile so that I don't end up landing on page.asp?id=<null> each time it doesn't find a match?
Back to Top View jakob's Profile Search for other posts by jakob
 
Vyacheslav
Moderator Group
Moderator Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 396
Posted: 17 July 2008 at 7:16am | IP Logged Quote Vyacheslav

Ok. First of all excuse me, because I have tested this rule with another file name: index.asp,
and forgot to replace it to page.asp
So rules for you looks like:
Code:
RewriteMap map txt:map.txt
RewriteMap lower int:tolower
                  
RewriteRule ^(page_with_redirect1)/?$ page.asp?id=${map:${lower:$1}} [NC,R=301,L]
RewriteRule ^(page_with_redirect2)/?$ page.asp?id=${map:${lower:$1}} [NC,R=301,L]

RewriteRule ^page\.asp$ - [L]
RewriteRule ^([^/]+)/?$ page.asp?id=${map:${lower:$1}}


Here is my map.txt:
Code:
one 1
two 2
three 3
page_with_redirect1 44
page_with_redirect2 55


Some examples:
1) If you go to: www.example.com/onepage, then it rewrites to www.example.com/page.asp?id=1
and in address bar you can see www.example.com/onepage

2) If you go to: www.example.com/page_with_redirect1, then it redirects to www.example.com/page.asp?id=44
and in address bar you can see www.example.com/page.asp?id=44

Of course, you may use many map-files. But I have offered the solution, with a single map file.

__________________
Kind regards!
Vyacheslav.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 
jakob
Newbie
Newbie


Joined: 16 October 2006
Online Status: Offline
Posts: 14
Posted: 17 July 2008 at 7:25am | IP Logged Quote jakob

Hi,

It just seems to me that I need to make a seperate RewriteRule for each page i want to redirect instead of rewrite..

That isn't optimal...

Also I don't see what RewriteRule ^page\.asp$ - [L] does.

Can't I somehow make a pattern that looks up wheither the value from the mapfile is numerical or not?
Back to Top View jakob's Profile Search for other posts by jakob
 
jakob
Newbie
Newbie


Joined: 16 October 2006
Online Status: Offline
Posts: 14
Posted: 17 July 2008 at 7:54am | IP Logged Quote jakob

I think I found the solution using 2 mapfiles (1 for rewrites, 1 for redirects)

Code:

RewriteCond ${mapfile:${lower:$1}|default} default
RewriteRule ^([^/]+)/?$ ${mapfile2:${lower:$1} [NC,L,R=301]
RewriteRule ^([^/]+)/?$ /page.asp?id=${mapfile:${lower:$1}} [NC,L,QSA]


where mapfile2 contains absolute addresses as values


Edited by jakob - 17 July 2008 at 7:55am
Back to Top View jakob's Profile Search for other posts by jakob
 
Vyacheslav
Moderator Group
Moderator Group


Joined: 02 July 2008
Location: Ukraine
Online Status: Offline
Posts: 396
Posted: 17 July 2008 at 8:10am | IP Logged Quote Vyacheslav

Ok. Of course you can use a single RewriteRule, but in this case the keys in your map-file
must have some identical part. E.g.: page_with_redirect_1,
page_with_redirect_2, page_with_redirect_3, etc.

And your rules will looks like:
Code:
RewriteMap map txt:map.txt
RewriteMap lower int:tolower
                   
RewriteRule ^(page_with_redirect(\d+))/?$ page.asp?id=${map:${lower:$1}} [NC,R=301,L]
RewriteRule ^page\.asp$ - [L]
RewriteRule ^([^/]+)/?$ page.asp?id=${map:${lower:$1}}


As for:
Code:
RewriteRule ^page\.asp$ - [L]

This rule passes rewriting.

__________________
Kind regards!
Vyacheslav.
Back to Top View Vyacheslav's Profile Search for other posts by Vyacheslav Visit Vyacheslav's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum