httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Schoenborn <scho...@cae.com>
Subject RE: [users@httpd] Rewrite Voodoo pt. 2
Date Mon, 25 Jan 2010 17:02:54 GMT

> Can you interpret:
>> 
>>  rewriteCond $(HOST_NAME) ^(.*)\.domain\.ext
> 
> Condition, proceed for host_name matching (anySubdomain).domain.ext
> 
>>  rewriteRule ^(.*)$ $(HOST_NAME)$1
> 
> Rule, I'm not sure what it does. Based on the link Tom posted, I'd
> guess that it takes everything after domain.ext and appends it after
> domain.ext - which would take an incoming URI request and output the
> URI unchanged. But that's my guess. I don't *know* what it does for
> sure. I could create a sandbox and test, but somehow that seems like
> it would be cheating.

This has come up a few times in this thread: you must remember that the URL does NOT include
the domain name. Therefore, the above rule takes the whole URL from beginning to end and *prepends*
the hostname so that in the subsequent rule (not shown above), you can also extract parts
of the host name (since parts are needed for rewritten the URL). 

> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4
> 
> Rule,
> lowercase-alpha saved as $1
> plus
> zero or more of everything saved as $2
> plus
> 0-9 numeric saved as $3
> plus
> domain.ext
> plus
> zero or more of anything saved as $4
> 
> rewrite to
> www$3.domain.ext/$2_$1$4

You got it so far...

> In the case of www.domain.ext/subdomain/file220110.html this would
> result in a severely fractured URL I think.

I was just given an example of how parts of the domain name can be extracted and put in URL
path with proper rules and conditions. 

>>  What will it do to the following HTTP requests:
> 
> Oh wow. Here we go. For URI's that match host_name:
> 
> rewriteRule ^([a-z])(.*)([0-9])\.domain\.ext(.*) www$3.domain.ext/$2_$1$4
> 
>>  domain.ext/something
> 
> www.domain.ext/something

Wrong: www.domain.ext does not match the condition so everything is skipped (I might have
forgotten a [C] on the first rule, sorry, didn't test)

> 
>>  asub2.domain.ext/something
> 
> www.domain.ext/2_asubsomething

You correctly parsed the rule earlier, according to which it would be 

www2.domain.ext/sub_asomething

but don't forget that there would actually be a slash right after the sub_a since something
will always start with a slash (except maybe in .htacces rules?)

>>  asub.domain.ext/something
> 
> www.domain.ext/_asubsomething
> 
> I think.

Wrong: the pattern for 2nd rule requires a digit just before the first dot of host name, so
rule will get skipped and URL unchanged.  

> 
> Reese
> 

It's really important to understand how the conditions and pattern matching work, together
with regexp. There may be other issues to consider when the rule is in an .htaccess (I gather
you only get part of the URL path then). 

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