httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Trutwin <j...@trutwins.homeip.net>
Subject Re: [users@httpd] RewriteMap questions
Date Wed, 30 May 2007 20:11:39 GMT
On Wed, 30 May 2007 15:06:27 -0400
"Joshua Slive" <joshua@slive.ca> wrote:

> On 5/30/07, Josh Trutwin <josh@trutwins.homeip.net> 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.

Thanks - great suggestions - now my next issue.  This is all done in
VirtualHosts, I noticed RewriteMap cannot be declared in a .htaccess
so I put it in the VirtualHost like so:

<VirtualHost *:80>
        VirtualDocumentRoot /httpd/%0/html
	RewriteMap rewriter dbm:/httpd/%0/html/rewrite_map.db 
</VirtualHost>

The RewriteMap doesn't seem to replace the %0 with the directory name
- so I have a directory /httpd/josh.test.com/html which has
rewrite_map.db.pag and rewrite_map.db.dir.  I created a .htaccess in
josh.test.com/html:

RewriteRule ^(.*) ${rewriter:$1} [R]

When attempting to access the site though I get a "No such file or
directory" error on /httpd/%0/html/rewrite_map.db.pag

Can I declare the RewriteMap once as above to map to each
VirtualHost's directory?

Thanks!  Feels like this is getting a lot closer.

Josh

---------------------------------------------------------------------
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@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message