Attention! Helicon Tech Blog has moved to

Friday, January 22, 2010

Titbits: dynamic mapfiles names

Not so long ago one of our clients urged us to test an interesting situation we've never tried before. The result was positive and saved him a lot of lines in the config file. Now we want to share this experience with you.

So, the conditions were:
  • about 300 mapfiles with the first part of name being the name of the city, e.g. london-map.txt, paris-map.txt, moscow-map.txt etc.;
  • the requests are made to the subdomains having the names of the cities, e.g.,, etc.;
  • requests to SEO-friendly URLs should be rewritten to the .asp page with the "id" taken from the corresponding mapfile and the "city" parameter being the city name.
To accomplish the above task with the least effort, we need the following.


london_seo_value1 11
london_seo_value2 22
london_seo_value3 33

paris_seo_value1 44
paris_seo_value2 55
paris_seo_value3 66

moscow_seo_value1 77
moscow_seo_value2 88
moscow_seo_value3 99

RewriteBase /

RewriteMap london-map txt:london-map.txt [NC]
RewriteMap paris-map paris-map.txt [NC]
RewriteMap moscow-map moscow-map.txt [NC]

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${%1-map:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^([^/]+)/?$ city.asp?city=%1&id=${%1-map:$1} [NC,L]

The idea is that the first part of mapfile name is dynamic and depends on the name of the subdomain being requested.

Now upon request to you'll be shown the content of And upon request to you'll be shown the content of

As you can see we have just one rule (instead of 300) which cares about all possible requests and deals with all existing mapfiles.

1 comment:

  1. you're talking about me, you solved my problem.

    thank you so much for your help.