Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Organization I'm working for is implementing a new CMS. As such, a vast number of URLs (say tens of thousands) will be being rewritten to new ones. Some of them may be 302'ed to the new URI pattern, like:

RewriteRule ^/articles/articlename.html /new/article/taxonomy/and/such.html [R,L]

Others, we'll want to pass-through to the CMS backend so that the end-user sees the same URL, though it's served from the new path internally, like

RewriteRule ^/articles/article2.html /content/en/new/article/path/article2.html [PT,L]

I was planning to put this in a pair of FAT DBM rewritemaps, so as to handle the two types separately, but faster than just putting them in there as thousands of individual rewrite rules.

I'm a unclear though, on how to call these so that mod_rewrite only picks up any URLs that match one of the keys in the DBM file, and then replace it with the value.

RewriteEngine on
RewriteMap 302_rewrites dbm:/etc/httpd/conf/rewritemaps/dbmtest_302.dbm
RewriteRule ^${302_rewrites:$1} ${302_rewrites:$2} [R,L]

The above doesn't work. But am I close?

share|improve this question

You can't use use your RewriteMap in the left-hand side (the match) of a RewriteRule. Additionally, since no match has occurred at that point, there's nothing in $1. You could specify a default value in the RewriteRule, like this:

RewriteRule ^(/articles/.*) ${302_rewrites:$1|$1} [R,L]

This will look up the request path (/articles/mumble/...) in your database, and if nothing is found, it will return the original path. If not everything starts with /articles you can obviously make your match more general:

RewriteRule ^(/.*) ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.