httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Cardwell <apache-us...@lists.grepular.com>
Subject Re: [users@httpd] mode_rewrite hostnames and wikiwords
Date Mon, 07 Jan 2008 11:05:56 GMT
Dragon wrote:

>> hit a snag
>>
>> how would I expand this rule to capture and convert the following?
>>
>> your.host.name -> YourHostName (works with rule)
>> YOUR.HOST.NAME -> YourHostName (currently not handled)
>> Yo-ur.HOST.name -> YourHostName (currently not handled)
>>
>> effectively the spec would be to take /doc/FQDN (regardless of case 
>> presented)
>> and capitaliseing every dot separated word returning
>> /doc/FullyQualifiedDomainName removing any characters other than 
>> [A-Z][a-z][0-9]

RewriteEngine On
RewriteMap    uppercase int:toupper
RewriteMap    lowercase int:tolower
RewriteRule   ^/doc/(.*)$                     /doc2/${lowercase:$1}
RewriteRule   ^/doc2/(.*?)[^.a-zA-Z0-9]+(.*)$ /doc2/$1$2                [N]
RewriteRule   ^/doc2/((.*)\.)?([a-z])(.*)$    /doc2/$2${uppercase:$3}$4 [N]
RewriteRule   ^/doc2/(.*)                     /wiki/$1                  [PT]

> If I were to do something like this, I would most likely use the 
> RewriteMap directive to pass the incoming URL to a short Perl script to 
> do the transformation. The stdin file handle presents the program with 
> the request URL and you pass the result back via the stdout file handle.
> 
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap
> 
> See the section on the page linked above entitled "External Rewriting 
> Program" for details and a skeleton Perl script you can add your 
> processing to.

IMO, you should only use external rewrite programs as a last resort. If 
you can use the inbuilt apache functions you should do so.

Regards,
Mike

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