| Author |
|
jakob Newbie

Joined: 16 October 2006
Online Status: Offline Posts: 14
|
| Posted: 17 July 2008 at 4:49am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Moderator Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 396
|
| Posted: 17 July 2008 at 5:36am | IP Logged
|
|
|
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 |
|
| |
jakob Newbie

Joined: 16 October 2006
Online Status: Offline Posts: 14
|
| Posted: 17 July 2008 at 6:14am | IP Logged
|
|
|
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 |
|
| |
jakob Newbie

Joined: 16 October 2006
Online Status: Offline Posts: 14
|
| Posted: 17 July 2008 at 6:57am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Moderator Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 396
|
| Posted: 17 July 2008 at 7:16am | IP Logged
|
|
|
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 |
|
| |
jakob Newbie

Joined: 16 October 2006
Online Status: Offline Posts: 14
|
| Posted: 17 July 2008 at 7:25am | IP Logged
|
|
|
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 |
|
| |
jakob Newbie

Joined: 16 October 2006
Online Status: Offline Posts: 14
|
| Posted: 17 July 2008 at 7:54am | IP Logged
|
|
|
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 |
|
| |
Vyacheslav Moderator Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 396
|
| Posted: 17 July 2008 at 8:10am | IP Logged
|
|
|
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 |
|
| |