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?
You can't use use your
RewriteMap
in the left-hand side (the match) of aRewriteRule
. Additionally, since no match has occurred at that point, there's nothing in$1
. You could specify a default value in theRewriteRule
, like this: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: