Boyle Owen wrote:
>> -----Original Message-----
>> From: Norman Khine [mailto:[EMAIL PROTECTED] 
>> Sent: Wednesday, September 06, 2006 9:23 AM
>> To: users@httpd.apache.org
>> Subject: [EMAIL PROTECTED] Dynamic RewriteRule based on the URL
>>
>> Hello,
>> Is it possible to create an Apache Rewrite rule so that the 
>> depending on
>> the sub-domain the server receives it is then re-written to a 
>> different
>> folder, for example, I have this working but want to reduce it to just
>> one rule:
>>
>> <VirtualHost *:80>
>>     ServerName  folder_A.domain.tld
>>     RewriteEngine On
>>     RewriteRule ^/(.*) http://localhost:9080/folder_A/$1 [P]
>>     RequestHeader set X-Base-Path folder_A
>>     ErrorLog       /var/log/apache2/folder_A-error_log
>>     CustomLog      /var/log/apache2/folder_A-access_log common
>> </VirtualHost>
>>
>> <VirtualHost *:80>
>>     ServerName  folder_B.domain.tld
>>     RewriteEngine On
>>     RewriteRule ^/(.*) http://localhost:9080/folder_B/$1 [P]
>>     RequestHeader set X-Base-Path folder_B
>>     ErrorLog       /var/log/apache2/folder_B-error_log
>>     CustomLog      /var/log/apache2/folder_B-access_log common
>> </VirtualHost>
>>     
>
> Take a look at RewriteCond - this allows you to make conditional
> redirects and so generate an if-else construct, eg:
>
> RewriteCond domainA
> RewriteRule to folder A
> RewriteCond domainB
> RewriteRule to folder B
>
> Of course, the rewrite directives then go in the main body of the config
> so they apply to all VHs. BTW, not sure if this is less or more
> work/effort than your original solution.. So I guess you're really
> looking for:
>
> RewriteRule to folder(domain)
>
> where the destination depends on the value of "domain"... I can't think
> of an easy way to do this - plough through the examples in
> http://httpd.apache.org/docs/2.2/misc/rewriteguide.html.
>
> Rgds,
> Owen Boyle
> Disclaimer: Any disclaimer attached to this message may be ignored. 
>
>
>   
>> etc...
>>
>>
>> So is there a nice way to reduce this to only one rule where if a
>> request is sent to folder_A.domain.tld the RewriteRule, 
>> RequestHandler,
>> ErrorLog, CustomLog entries are changed accordingly?
>>
>> Perhaps something like in the line of %{SERVER_NAME}:
>>
>> <VirtualHost *:80>
>>     ServerName  %{FOLDER_NAME}.domain.tld
>>     RewriteEngine On
>>     RewriteRule ^/(.*) http://localhost:9080/%{FOLDER_NAME}/$1 [P]
>>     RequestHeader set X-Base-Path %{FOLDER_NAME}
>>     ErrorLog       /var/log/apache2/%{FOLDER_NAME}-error_log
>>     CustomLog      /var/log/apache2/%{FOLDER_NAME}-access_log common
>> </VirtualHost>
>>
>>
>> Would this work and how would you set the %{FOLDER_NAME} if 
>> it does or is there a different approach?
>>
>> Many thanks
>>
>>
>> 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: [EMAIL PROTECTED]
>>    "   from the digest: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>     
>  
>  
> This message is for the named person's use only. It may contain confidential, 
> proprietary or legally privileged information. No confidentiality or 
> privilege is waived or lost by any mistransmission. If you receive this 
> message in error, please notify the sender urgently and then immediately 
> delete the message and any copies of it from your system. Please also 
> immediately destroy any hardcopies of the message. You must not, directly or 
> indirectly, use, disclose, distribute, print, or copy any part of this 
> message if you are not the intended recipient. The sender's company reserves 
> the right to monitor all e-mail communications through their networks. Any 
> views expressed in this message are those of the individual sender, except 
> where the message states otherwise and the sender is authorised to state them 
> to be the views of the sender's company.
>
> ---------------------------------------------------------------------
> 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: [EMAIL PROTECTED]
>    "   from the digest: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>   
Thanks for your reply, I was looking at the
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html documentation
and perhaps something like this may work...

RewriteEngine on
RewriteCond   %{*HTTP_HOST*}                 *[^.]+*\.host\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   *([^.]+)*\.host\.com(.*) http://localhost:9080/*$1*$2 [P]

RequestHeader set X-Base-Path %{*HTTP_HOST*}

#Not sure if the logs entry is correct

ErrorLog       /var/log/apache2/%{*HTTP_HOST*}-error_log
CustomLog      /var/log/apache2/%{*HTTP_HOST*}-access_log common

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: [EMAIL PROTECTED]
   "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to