You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Phil Wild <ph...@gmail.com> on 2008/01/04 15:17:03 UTC
[users@httpd] mode_rewrite hostnames and wikiwords
Hello apache experts:-)
I am trying to rewrite a url which conatins a hostname, converting the
hostname to a wikiword.
What I have so far is:
RewriteRule ^/doc/([a-z,A-Z]*.*)\.([a-z,A-Z]*.*)$ /doc/$1$2 [N]
RewriteRule ^/doc/([A-Z]*.*)$ /twiki/bin/view/Main/$1 [PT]
which takes a URL that looks like
http://www.example.com/doc/hostname.example.com
and runs it as
http://www.example.com/doc/hostnameexamplecom
which is close but I would really like to run it as
http://www.example.com/doc/HostnameExampleCom
Is this possible and if so, how is it done?
Many thanks
Phil
---------------------------------------------------------------------
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Phil Wild <ph...@gmail.com>.
Hi Mike,
Thanks I will give it a go.
On the suggestion of external code, I was going to use the below
#!/usr/bin/perl -w
while (<STDIN>) {
s/([a-zA-Z0-9]+)/\u\L$1/g;
s/[^a-zA-Z0-9\n]//g;
print;
}
but I like the idea of doing it all in the apache config over using the above.
Many thanks again
Phil
On 07/01/2008, Mike Cardwell <ap...@lists.grepular.com> wrote:
> Mike Cardwell wrote:
>
> >>> 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]
>
> Actually, on second thoughts, a neater method (avoiding doc2) would be:
>
> RewriteEngine On
> RewriteMap uppercase int:toupper
> RewriteMap lowercase int:tolower
> RewriteRule ^/doc/(.*)$ /wiki/${lowercase:$1}
> RewriteRule ^/wiki/(.*?)[^.a-zA-Z0-9]+(.*)$ /wiki/$1$2 [N]
> RewriteRule ^/wiki/((.*)\.)?([a-z])(.*)$ /wiki/$2${uppercase:$3}$4 [N]
> RewriteRule ^/wiki/(.*) /wiki/$1 [PT]
>
> They both pretty much work the same though.
>
> 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
>
>
--
Tel: 0400 466 952
Fax: 0433 123 226
email: philwild@gmail.com
---------------------------------------------------------------------
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Mike Cardwell <ap...@lists.grepular.com>.
Mike Cardwell wrote:
>>> 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]
Actually, on second thoughts, a neater method (avoiding doc2) would be:
RewriteEngine On
RewriteMap uppercase int:toupper
RewriteMap lowercase int:tolower
RewriteRule ^/doc/(.*)$ /wiki/${lowercase:$1}
RewriteRule ^/wiki/(.*?)[^.a-zA-Z0-9]+(.*)$ /wiki/$1$2 [N]
RewriteRule ^/wiki/((.*)\.)?([a-z])(.*)$ /wiki/$2${uppercase:$3}$4 [N]
RewriteRule ^/wiki/(.*) /wiki/$1 [PT]
They both pretty much work the same though.
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Mike Cardwell <ap...@lists.grepular.com>.
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Dragon <dr...@crimson-dragon.com>.
Phil Wild did speak thusly:
>Hmmm
>
>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]
---------------- End original message. ---------------------
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.
Dragon
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Venimus, Saltavimus, Bibimus (et naribus canium capti sumus)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------------------------------------------------------------------
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Phil Wild <ph...@gmail.com>.
Hmmm
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]
Many thanks
Phil
On 07/01/2008, Phil Wild <ph...@gmail.com> wrote:
> Hi Mike,
>
> This worked a treat....
>
> many thanks for your help and knowledge...
>
> Phil
>
> On 05/01/2008, Mike Cardwell <ap...@lists.grepular.com> wrote:
> > Phil Wild wrote:
> >
> > > Hello apache experts:-)
> > >
> > > I am trying to rewrite a url which conatins a hostname, converting the
> > > hostname to a wikiword.
> > >
> > > What I have so far is:
> > >
> > > RewriteRule ^/doc/([a-z,A-Z]*.*)\.([a-z,A-Z]*.*)$ /doc/$1$2 [N]
> > > RewriteRule ^/doc/([A-Z]*.*)$ /twiki/bin/view/Main/$1 [PT]
> > >
> > > which takes a URL that looks like
> > >
> > > http://www.example.com/doc/hostname.example.com
> > >
> > > and runs it as
> > >
> > > http://www.example.com/doc/hostnameexamplecom
> > >
> > > which is close but I would really like to run it as
> > >
> > > http://www.example.com/doc/HostnameExampleCom
> > >
> > > Is this possible and if so, how is it done?
> >
> > Something like this maybe?
> >
> > RewriteEngine On
> > RewriteMap uppercase int:toupper
> > RewriteRule ^/doc/((.*)\.)?([a-z])(.*)$ /doc/$2${uppercase:$3}$4 [N]
> > RewriteRule ^/doc/(.*) /twiki/bin/view/Main/$1 [PT]
> >
> > 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
> >
> >
>
>
> --
> Tel: 0400 466 952
> Fax: 0433 123 226
> email: philwild@gmail.com
>
--
Tel: 0400 466 952
Fax: 0433 123 226
email: philwild@gmail.com
---------------------------------------------------------------------
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Phil Wild <ph...@gmail.com>.
Hi Mike,
This worked a treat....
many thanks for your help and knowledge...
Phil
On 05/01/2008, Mike Cardwell <ap...@lists.grepular.com> wrote:
> Phil Wild wrote:
>
> > Hello apache experts:-)
> >
> > I am trying to rewrite a url which conatins a hostname, converting the
> > hostname to a wikiword.
> >
> > What I have so far is:
> >
> > RewriteRule ^/doc/([a-z,A-Z]*.*)\.([a-z,A-Z]*.*)$ /doc/$1$2 [N]
> > RewriteRule ^/doc/([A-Z]*.*)$ /twiki/bin/view/Main/$1 [PT]
> >
> > which takes a URL that looks like
> >
> > http://www.example.com/doc/hostname.example.com
> >
> > and runs it as
> >
> > http://www.example.com/doc/hostnameexamplecom
> >
> > which is close but I would really like to run it as
> >
> > http://www.example.com/doc/HostnameExampleCom
> >
> > Is this possible and if so, how is it done?
>
> Something like this maybe?
>
> RewriteEngine On
> RewriteMap uppercase int:toupper
> RewriteRule ^/doc/((.*)\.)?([a-z])(.*)$ /doc/$2${uppercase:$3}$4 [N]
> RewriteRule ^/doc/(.*) /twiki/bin/view/Main/$1 [PT]
>
> 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
>
>
--
Tel: 0400 466 952
Fax: 0433 123 226
email: philwild@gmail.com
---------------------------------------------------------------------
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
Re: [users@httpd] mode_rewrite hostnames and wikiwords
Posted by Mike Cardwell <ap...@lists.grepular.com>.
Phil Wild wrote:
> Hello apache experts:-)
>
> I am trying to rewrite a url which conatins a hostname, converting the
> hostname to a wikiword.
>
> What I have so far is:
>
> RewriteRule ^/doc/([a-z,A-Z]*.*)\.([a-z,A-Z]*.*)$ /doc/$1$2 [N]
> RewriteRule ^/doc/([A-Z]*.*)$ /twiki/bin/view/Main/$1 [PT]
>
> which takes a URL that looks like
>
> http://www.example.com/doc/hostname.example.com
>
> and runs it as
>
> http://www.example.com/doc/hostnameexamplecom
>
> which is close but I would really like to run it as
>
> http://www.example.com/doc/HostnameExampleCom
>
> Is this possible and if so, how is it done?
Something like this maybe?
RewriteEngine On
RewriteMap uppercase int:toupper
RewriteRule ^/doc/((.*)\.)?([a-z])(.*)$ /doc/$2${uppercase:$3}$4 [N]
RewriteRule ^/doc/(.*) /twiki/bin/view/Main/$1 [PT]
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