RedirectRule with RewriteMap not working.

Topics: Developer Forum
Mar 10, 2010 at 6:50 PM

I am using IIRF 2.x.

I want to 301 redirect a large volume of pages that use underscores to the more favourable dashes. I basically want the flow of the IIRF.ini file to be this:

1- if you find this url in the map file, rewrite it.
2- if not, then skip it.

I've created a .txt map file (with just one entry for testing purposes) named Auto-Racing-301-Map.txt. The file contains a single line:
auto_test_page.html        auto-test-page.html

In my ini file I define the map here:
RewriteMap automap txt:D:\inetpub\IIRF-Maps\Auto-Racing-301-Map.txt

Then I have this as my RedirectRule:
RedirectRule ^/Auto_Racing/(.*) /auto-racing/${automap:$1} [R=301,I]

However what I'm getting redirected to is this:
http://www.mydomain.com/auto-racing/$%7Bautomap:auto_test_page.html%7D

 

I got the example right out of the docs so I'm not sure what to do. Any help is greatly appreciated, thanks.

 

Mar 10, 2010 at 6:59 PM

I should have done this first, but...

I just turned on logging and checked the log file. I'm getting the following error:

Wed Mar 10 11:54:00 - 5344 - ReadSiteConfig: WARNING: line 34: unrecognized directive, ignoring it: 'RewriteMap'

This is obviously the root of the problem, but I got the RewriteMap example right out of the docs.

Mar 10, 2010 at 7:05 PM

Why the heck couldn't I figure this out _before_ I posted on here? I literally spent an hour before deciding to post and then I post and 5 minutes later I know the problem.

It seems RewriteMap is new in v2.1. It appears my hosting provider has version 2.0.

I will ask my hosting provider to install the new version.

Mar 10, 2010 at 7:15 PM

The saga continues... where the heck can I get IIRF.dll version 2.1?

Mar 10, 2010 at 7:23 PM

Ok, found it.

Coordinator
Mar 10, 2010 at 9:51 PM
Edited Mar 10, 2010 at 9:55 PM

Glad you figured all that out. . .  .

RewriteMap is, indeed, new to v2.1. 

However, I don't believe  you need RewriteMap in order to blanket replace underscores with dashes. 

It's enough to do a generic rule like this:

RedirectRule  ^/([^_]+)_([^_]+)$    http://server/$1-$2  [L]

The above works for a single underscore.  If you need additional underscores, use additional rules, like this:

RedirectRule  ^/([^_]+)_([^_]+)_([^_]+)$    http://server/$1-$2-$3   [L]

...and so on.  

 

Mar 11, 2010 at 1:12 PM

Thanks Cheeso. I'm actually doing a little more than just replacing underscores. I was just trying to be brief in my explanation. Regarding replacing underscores, is there no other way to do a "replaceAll()" type action? There are a variable number of underscores with no upper or lower limits to the number that may occur in a file name.

For instance a file name may be:

this_file.html

or it may be

this_is_a_file_about_some_topic_or_other.html