Re: [users@httpd] Dynamic RewriteRule based on the URL

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

 



Arjun Datta wrote:
> Hi Folks,
>
> Simple question,
>
> I was reading the documentation for mod_proxy module in version 2.2 on the
> apache.org website and I was a little confused by the difference between
> forward and reverse proxies.
>
> My understanding:
> Forward returns the addresses and reverse (default) returns the content.  Is
> this true ?
>
> Regards,
> Arjun
>
> -----Original Message-----
> From: jslive@xxxxxxxxx [mailto:jslive@xxxxxxxxx]On Behalf Of Joshua
> Slive
> Sent: Thursday, September 07, 2006 9:36 AM
> To: users@xxxxxxxxxxxxxxxx
> Subject: Re: [users@httpd] Dynamic RewriteRule based on the URL
>
>
> On 9/7/06, Norman Khine <norman@xxxxxxxxx> wrote:
>
>   
>> [1] <VirtualHost *:80>
>>
>> [2]    ServerName  domain.tld
>> [3]    RewriteEngine on
>> [4]    RewriteCond   %{*HTTP_HOST*}    *[^.]+*\.domain\.tld$
>> [5]    RewriteRule   ^(.+)             %{HTTP_HOST}$1
>>     
> [C]
>   
>> [6]    RewriteRule   *([^.]+)*\.domain\.tld(.*)
>>     
> http://localhost:9080/*$1*$2 [P]
>   
>> [7]    RequestHeader set X-Base-Path %{*HTTP_HOST*}
>>
>> [8]    ErrorLog       /var/log/apache2/all-error_log
>> [9]    CustomLog      /var/log/apache2/all-access_log common
>>
>> [0] </VirtualHost>
>>
>>
>> I don't understand line [2], as the server gets the request
>>     
> http://folder.domain.tld as this points to an A record IP address Apache
> will return the default page and it stops, how do I inject the
> %{*HTTP_HOST*} value or is there some magic I am missing and don't see?
>   
>> Assuming that there is, Apache then switches the RewriteEngine on [3] and
>>     
> takes everything before domain.tld - what is the meaning of [^.]+ ? then the
> [C] means continue to the next RewriteRule which in my case needs to rewrite
> to an internal server and Proxy this i.e. [P], but this does not work for me
> either ;'(
>   
>> Line [7] I need to set the X-Base-Path to the folder name.
>>
>> I would like to avoid using vhost.map or any scripting but I am open to
>>     
> suggestions if there is no other way ;)
>   
>> By the way, I don't have the www.'folder'.domain.tld in my URL - maybe
>>     
> this is the problem, but don't see why?
>
> I don't understand that last line.  But here is something that should be
> closer:
> <VirtualHost *:80>
> ServerName  domain.tld
> ServerAlias *.domain.tld
> RewriteEngine on
> RewriteCond   %{HTTP_HOST}    ^([a-zA-Z_]+\.domain\.tld)$
> RewriteRule (.+) http://localhost:9080/%1$1 [P,E=THEHOST:%1]
>
> RequestHeader set X-Base-Path %{THEHOST}e
> ErrorLog       /var/log/apache2/all-error_log
> CustomLog      /var/log/apache2/all-access_log common
> </VirtualHost>
>
> I don't know if this will work, but it is closer than what you have.
> A few notes:
> 1. My regex matching the HOST is more strict to avoid clients playing
> funny games with their host header and causing security problems.  It
> accepts only hostnames containing letters and the underscore
> character.
> 2. In the RewriteRule %1 matches the regex from the RewriteCond and $1
> matches the regex from the RewriteRule.
> 3. The funky stuff with THEHOST is necessary because the RequestHeader
> directive cannot access mod_rewrite variables.  So I instead have
> mod_rewrite shove HTTP_HOST in an environment variable.
>
> One more note: I'm not actually sure whether RequestHeader can use env
> variables at all.  You'd need to check the code to be sure.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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
>
>
> ---------------------------------------------------------------------
> 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
>
>   
Hi,
here is a good explanation of the differences.

http://apache.active-venture.com/mod/mod_proxy2.html

Cheers

Norman

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