On 5/30/07, Josh Trutwin <josh@xxxxxxxxxxxxxxxxxxx> wrote:
I have been asked to create rewrite rules for sites that use an old page naming scheme to a new one. The first attempt was to create a .htaccess file that had a rewrite rule for every page, something like: RewriteRule ^new_page_name.php$ /sitepages/pid123.php [L,QSA,NC] Works ok for small sites, but some of them have thousands of pages which translates to thousands of RewriteRules which of course bogs down the apache server. I was going to look at creating a rewritemap using a .db hash file - my main concern is that we have some existing URL's that map to actual files on the system. My thought was to do something like this: RewriteMap existing prg:/path/to/file/map.pl RewriteMap redirects dbm:/path/to/file/map.db RewriteRule ^/(.*) ${existing:$1} [L,QSA] RewriteRule ^/(.*) ${redirects:$1} [L,QSA] My thought being that the first map is a program that tests if the URL matches an actual file/dir in the doc root, returning NULL if it doesn't. If it matches then processing would stop and the first RewriteRule would work. But if it doesn't match, does the second RewriteRule even get executed? If not, do I then have to resort to a single map that is a perl program that first checks if the URL maps to a page and if not manually reads the map file? Also, curious if anyone has a PhP example of a map program, I'm a little more proficient in that - or even python...
Don't use a map program if you can avoid it. The dbm maps are safer and faster. What you want is easy enough to get, using something like RewriteCond ${existing:$1|NOT-FOUND} =NOT-FOUND RewriteRule ^/(.*) ${redirects:$1} [L,QSA] You could also, if you want, simply use a RewriteCond to test if the file being requested exists on the filesystem. See the -d and -f tests. Joshua. --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx