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

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

 



Joshua Slive wrote:
> 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
>
Hi no this did not work, I have this Apache error in the logs

[Thu Sep 07 00:51:50 2006] [error] [client 192.168.4.90] File does not
exist: /usr/htdocs

And on the access_log I get the 404 Error -- "GET / HTTP/1.1" 404 270
"-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6"

but only if I access the domain.tld site

if I try anything else such as folder_A.domain.tld the apache log does
not register anything and I get a 502 Bad Gateway Error

Will play more and thanks for your advise.

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