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. london.domain.com, paris.domain.com, moscow.domain.com 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 http://paris.domain.com/paris_seo_value1 you’ll be shown the content of http://www.domain.com/city.asp?city=paris&id=44. And upon request to http://moscow.domain.com/moscow_seo_value3 you’ll be shown the content of http://www.domain.com/city.asp?city=moscow&id=99.

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

This entry was posted in ISAPI_Rewrite and tagged . Bookmark the permalink.

One Response to Titbits: dynamic mapfiles names

  1. Anonymous says:

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

    thank you so much for your help.