Re: [users@httpd] mod_rewrite vs Content Management Systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Aug 07, 2005 at 02:35:50PM -0400, John Hicks wrote:
> mod_rewrite can do a good job of translating urls like the above into 
> something like this:
> 
> www.geozoo.com/?Audience=kids&Subject=Carnivora
> etc.
> 
> which most any CMS can go to town with.
> 
> . . .
> 
> >One other question: I read somewhere that you can
> >actually produce several URL's for one article. For
> >example, an article about the wolf might be accessed
> >at any of the following:
> >
> >www.geozoo.org/stacks/wolf/
> >www.geozoo.org/stacks/Canis_lupus/
> >www.geozoo.org/stacks/top_predator/
> >
> >I think I read about this on Plone's website, but
> >Plone is way over my head. Is this something you can
> >do with mod_rewrite or some other technology that
> >isn't restricted to a particular CMS? Can it be done
> >with a database? (I'll have the wolf listed under
> >wolf, Canis_lupus, top predator, etc.)
> 
> mod_rewrite uses regular expressions. You'd only need a few to do the 
> basic job. But if you want to do rewrites based on particular subjects, 
> the list of rewrite rules would get way longer and maintenance (of 
> regular expressions) would be a bear.
> 
> Assuming you have a pretty long assortment of critters, you'd do better 
> to do this with your CMS using a database.

You can however get mod_rewrite to do its own database lookups, and it's
pretty efficient.

(1) using dbm files, e.g.

    RewriteMap      articlemap                  dbm:/conf/articlemap

    RewriteCond     ${articlemap:$1}            ^(.+)$
    RewriteRule     /stacks/([^/]+)(/?.*)$      %1$2

Then if /conf/articlemap contains

    wolf		/articles/wolf
    canis_lupus		/articles/wolf
    top_predator	/articles/wolf

and you convert this to /conf/articlemap.db, then an access to

    /stacks/top_predator/foo.html
will be rewritten to
    /articles/wolf/foo.html

You can stick a [R,L] on the end of the line if this is a URI you wish to
redirect the browser to. Also you might want to make it case-insensitive:

    RewriteMap      articlemap                  dbm:/conf/articlemap
    RewriteMap      tolower                     int:tolower

    RewriteCond     ${articlemap:${tolower:$1}} ^(.+)$
    RewriteRule     /stacks/([^/]+)(/?.*)$      %1$2

The logic takes a strange path if you're not familiar with it:

- first the URI is matched against the regexp in the LHS of the RewriteRule
- if it matches, then the RewriteConds above it are tried
- if the RewriteConds match successfully, then the rewriting on the RHS of
the RewriteRule is done.

(2) using an external rewriting process. Lookup syntax is the same as above,
but you write an external script (e.g. in perl or whatever language you're
happy with) which performs the lookup in whatever way you like, e.g. from a
hash in memory, from a SQL database etc.

Regards,

Brian.

---------------------------------------------------------------------
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



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux