RewriteMaps, QueryStrings and MediaTemple

Tech Notes

So we needed to migrate one of our last isEngine sites to an archived (not database driven) site with modern CSS and jQuery. The old site was stored in XML so we built a Python script to migrate the content into new templates and store a sitemap and an ID map. When it came time to translate the URLs using Apache Rewrite I had several go's at getting it working. The recipe is as follows. A RewriteMap directive. This cannot be in an .htaccess file or in a <Directory> directive. It must be in a <VirtualHost> directive. In mediatemple that meant adding it to the root and sub domain conf/vhost.conf file (even though we were working in a subdomain). $ cat conf/vhost.conf RewriteMap dynamic2static "txt:/var/www/vhosts/" $ /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost $ /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost $ /sbin/service httpd graceful Also in order to redirect URLs containing cgi-bin I needed to disable the overriding ScriptAlias in the main server config file. I changed it to cgi instead. $ vi /etc/httpd/conf/httpd.conf # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" ScriptAlias /cgi/ "/var/www/cgi-bin/" $/sbin/service httpd graceful Next our rewrite map file. Here are the first 10 lines. 1191 1272 1283 1294 1495 1306 1317 1328 1339 13410 And finally our .htaccess file. Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteCond %{QUERY_STRING} id=(\d+)$ RewriteRule ^cgi-bin/isengine$ /story/${dynamic2static:%1|NOTFOUND}? [L] RewriteRule ^Prompt/(\d+)$ /story/${dynamic2static:$1|NOTFOUND}? [L] The interesting lines are RewriteCond %{QUERY_STRING} id=(\d+)$ Only apply the following rule if we can match a query string ending with id=[some integer] RewriteRule ^isengine$ /story/${dynamic2static:%1|NOTFOUND}? [L] If the URL ended with isengine then rewrite it to story/ followed by our matched id (%1) mapped using our dynamic2static map. eg: becomes