You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Oliver Schoenborn <sc...@cae.com> on 2009/12/15 23:10:46 UTC

[users@httpd] best way to modify a URL

I have a simple problem:   the URL root for a client website we are setting up is http://foo.com/bar/*, but our client wants access to be it via http://dodo.foo.com<http://qun.foo.com>/*, how would I set this up? I have used mod_proxy in the past for something similar but this doesn't seem to be applicable here. I think mod_rewrite could handle it but it is rather complicated to learn in short time, if there is a simpler way or an example somewhere a link would be greatly appreciated. Cheers,
Oliver


RE: [users@httpd] best way to modify a URL

Posted by Oliver Schoenborn <sc...@cae.com>.
Thanks Justin. I have tried playing around with rules based on what you posted. My findings are in my reply to Andre, which I hope will be clearer than original, if you would like to take another stab at it. Regards, 
Oliver



> -----Original Message-----
> From: Justin Pasher [mailto:justinp@newmediagateway.com]
> Sent: December 15, 2009 6:14 PM
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] best way to modify a URL
> 
> Oliver Schoenborn wrote:
> >
> > I have a simple problem: the URL root for a client website we are
> > setting up is http://foo.com/bar/*, but our client wants access to be
> > it via http://dodo.foo.com/*, how would I set
> > this up? I have used mod_proxy in the past for something similar but
> > this doesn’t seem to be applicable here. I think mod_rewrite could
> > handle it but it is rather complicated to learn in short time, if
> > there is a simpler way or an example somewhere a link would be
> > greatly appreciated. Cheers,
> >
> > Oliver
> >
> 
> Could you just create a new VirtualHost container for
> http://dodo.foo.com/ and point the DocumentRoot to whatever file system
> directory corresponds to http://foo.com/bar/ ? That would probably be
> the easiest.
> 
> If not, you can use a RewriteRule to map the traffic. Something like
> this (untested):
> 
> RewriteRule ^/bar/(.*) http://dodo.foo.com/$1 [L]
> 
> 
> --
> Justin Pasher
> 
> 
> ---------------------------------------------------------------------
> 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


---------------------------------------------------------------------
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] best way to modify a URL

Posted by Justin Pasher <ju...@newmediagateway.com>.
Oliver Schoenborn wrote:
>
> I have a simple problem: the URL root for a client website we are 
> setting up is http://foo.com/bar/*, but our client wants access to be 
> it via http://dodo.foo.com <http://qun.foo.com>/*, how would I set 
> this up? I have used mod_proxy in the past for something similar but 
> this doesn’t seem to be applicable here. I think mod_rewrite could 
> handle it but it is rather complicated to learn in short time, if 
> there is a simpler way or an example somewhere a link would be greatly 
> appreciated. Cheers,
>
> Oliver
>

Could you just create a new VirtualHost container for 
http://dodo.foo.com/ and point the DocumentRoot to whatever file system 
directory corresponds to http://foo.com/bar/ ? That would probably be 
the easiest.

If not, you can use a RewriteRule to map the traffic. Something like 
this (untested):

RewriteRule ^/bar/(.*) http://dodo.foo.com/$1 [L]


-- 
Justin Pasher


---------------------------------------------------------------------
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] best way to modify a URL

Posted by André Warnier <aw...@ice-sa.com>.
>> 2. major issue: form POST problem: form POST should probably not get 
>> redirected either, but so far I can't find what condition to test for
>>
Purely as an aside :

Redirecting a POST internally is not a problem, because it happens 
early, before Apache even starts to read the request body (so to speak).

Redirecting a POST externally (through a browser re-direct response) is 
more of a problem, because then the browser has to re-submit the entire 
POST a second time, and browsers are inconsistent about that.

But POST is not a problem with Virtual Hosts, because if your website is 
correctly structured, browser will be talking to the correct Host right 
away.




---------------------------------------------------------------------
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] best way to modify a URL

Posted by Oliver Schoenborn <sc...@cae.com>.

From: André Warnier [aw@ice-sa.com]
>>> Considering your latest answer, I am also now inclined to think that
>>> using <VirtualHost> sections would be much cleaner.
>>
>> More efficient, more maintainable, or less code to write to obtain same effect?
>>
> Probably all of the above.
> General idea :

What I probably should have mentioned is that the actual server is on a different machine: 

router (port 80): forward to main server (foo.com)
main server (call it main for simplicity): one Apache server running on port 80
aux server 1 (say, 192.168.3.2, call it aux1): one Apache server running on port 80

The web application running on aux1 can't be modified, and its apache server config should not be touched unless absolutely impossible to do it any other way, so all its content has href's and POST etc that start with /bar/. 

Until now, I had main setup as reverse proxy to access aux1 from WAN: 

ProxyRequests Off
ProxyPass        /bar/ http://192.168.3.2/bar/
ProxyPassReverse /bar/ http://192.168.3.2/bar/

which works fine. 

However the client always sees Location as http://foo.com/bar/*, so recently we were asked if we could hide the /bar/ part and instead access aux1 via http://dodo.foo.com. 

I've spent a couple hours trying various things with the rewriterule to handle the POST requests but can't get it to work:

RewriteCond   %{HTTP_HOST}         ^dodo\.foo\.com$
RewriteCond   %{REQUEST_METHOD}    !GET                      [NC] 
RewriteRule   ^/bar/(.*)           http://foo.com/bar/$1     [P,L]

(tried many different combinations of R, P, L, and the URL substitution to /$1 etc but no success.

So looking at the VirtualHost option, yes perhaps cleaner, but can't get the client's Location to show the friendly URL: 

<VirtualHost *:80>
   ServerName dodo.foo.com
   ProxyRequests off
   ProxyPass           /bar/     http://192.168.3.2/bar/
   ProxyPassReverse    /bar/     http://192.168.3.2/bar/
   ProxyPass           /         http://192.168.3.2/bar/
   ProxyPassReverse    /         http://192.168.3.2/bar/

   #Redirect      permanent /bar/      http://dodo.foo.com/
   #RedirectMatch permanent /bar/(.*)  http://dodo.foo.com/$1
</VirtualHost>

Uncommenting either of the redirect lines doesn't help. 

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
---------------------------------------------------------------------
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] best way to modify a URL

Posted by André Warnier <aw...@ice-sa.com>.
Oliver Schoenborn wrote:
>>> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
>>> RewriteRule   ^/bar/(.*)               /$1    [R,L]
>>>
>>> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
>>> RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
>>> RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [P]
>>>
>> Also, in your example above, for me instinctively the last 3 rules look
>> like you are doing some extra work that should not be necessary :
>> - you test if the host name is "dodo.foo.com"
>> - then you modify the URL to add this hostname in front of the URL
>> - only to strip it out again and redirect to "foo.com/bar/" with a proxy
>> rule
> 
> Good point. I'll have to see if I can combine them, I based those two rules on an example, but I may be able to get away with 
> 
> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
> RewriteRule   ^(.*)    http://foo.com/bar/$1   [P]
> 
> There are a couple other issues: 
> 1. minor performance issue: all CSS and javascript etc (which all start with /bar/ in URL) do not need a redirect so I should probably filter those out if possible
> 2. major issue: form POST problem: form POST should probably not get redirected either, but so far I can't find what condition to test for
> 
>> Considering your latest answer, I am also now inclined to think that
>> using <VirtualHost> sections would be much cleaner.
> 
> More efficient, more maintainable, or less code to write to obtain same effect?
> 
Probably all of the above.
General idea :

Listen *:80
NameVirtualHost *:80

<VirtualHost *:80>
   Servername foo.com
   DocumentRoot /var/www/foo.com/docs

... (anything belonging to foo.com)

</VirtualHost>

<VirtualHost *:80>
   Servername dodo.foo.com
   DocumentRoot /var/www/dodo.foo.com/docs   (**)

... (anything belonging to dodo.foo.com)

</VirtualHost>

and just forget about redirecting/proxying from dodo.foo.com to foo.com/bar.

Now go read about Virtual Hosts.  That's what this stuff was created for 
: run 2 or more websites on the same Apache.  Your recently acquired 
knowledge about proxying and rewriting URLs will not be lost.  But maybe 
this is not the best place to use it.

http://httpd.apache.org/docs/2.2/vhosts/

(**) if you really insist, this could be
   DocumentRoot /var/www/foo.com/docs/bar
but I believe that this complicates the maintenance and programming.




---------------------------------------------------------------------
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] best way to modify a URL

Posted by Oliver Schoenborn <sc...@cae.com>.
>> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
>> RewriteRule   ^/bar/(.*)               /$1    [R,L]
>>
>> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
>> RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
>> RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [P]
>>
> Also, in your example above, for me instinctively the last 3 rules look
> like you are doing some extra work that should not be necessary :
> - you test if the host name is "dodo.foo.com"
> - then you modify the URL to add this hostname in front of the URL
> - only to strip it out again and redirect to "foo.com/bar/" with a proxy
> rule

Good point. I'll have to see if I can combine them, I based those two rules on an example, but I may be able to get away with 

RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^(.*)    http://foo.com/bar/$1   [P]

There are a couple other issues: 
1. minor performance issue: all CSS and javascript etc (which all start with /bar/ in URL) do not need a redirect so I should probably filter those out if possible
2. major issue: form POST problem: form POST should probably not get redirected either, but so far I can't find what condition to test for

> Considering your latest answer, I am also now inclined to think that
> using <VirtualHost> sections would be much cleaner.

More efficient, more maintainable, or less code to write to obtain same effect?


---------------------------------------------------------------------
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
---------------------------------------------------------------------
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] best way to modify a URL

Posted by André Warnier <aw...@ice-sa.com>.
Oliver Schoenborn wrote:
> 
> In order to apply the proxying just for dodo.foo.com only, I use a rewrite rule. Here is what I have so far, seems to work completely: 
> 
> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
> RewriteRule   ^/bar/(.*)               /$1    [R,L]
> 
> RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
> RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
> RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [P]
> 
> The [R,L] of first rule causes a redirect to client and the rule processing ends so client will just make a new request with the /bar/ stripped out, AND client browser will show the redirected URL. The [P] in second rule will cause proxying, but only for requests to dodo.foo.com, so client will NOT see that foo.com/bar is really the URL used. Time will tell if there are any corner cases that this doesn't cover. But boy, that rewrite module is powerful stuff!
> 
The main aspect is that you understand what is going on.
Now you can fly with your own wings.
In the second part of my answer, I was trying to avoid doing an external 
redirect, because :
- it is less efficient in terms of bandwidth : you add a round-trip to 
the browser and back
- it is less efficient in terms of your server : you have to process 2 
consecutive requests, instead of just one
- even for a fleeting moment, the browser is aware of the redirection, 
while if you do the redirection entirely inside of Apache, the browser 
never sees anything, and thinks the whole time that it is talking to 
dodo.foo.com

Also, in your example above, for me instinctively the last 3 rules look 
like you are doing some extra work that should not be necessary :
- you test if the host name is "dodo.foo.com"
- then you modify the URL to add this hostname in front of the URL
- only to strip it out again and redirect to "foo.com/bar/" with a proxy 
rule
It may all work, but it seems terribly heavy.
Maybe I'm wrong though.


Considering your latest answer, I am also now inclined to think that 
using <VirtualHost> sections would be much cleaner.




---------------------------------------------------------------------
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] best way to modify a URL

Posted by Oliver Schoenborn <sc...@cae.com>.
Thanks Andre for the detailed explanations. Looks like I have it figured out: 

From: André Warnier [aw@ice-sa.com]
>>
>> 1. Client goes to http://dodo.foo.com:
>>   A. server changes this to http://foo.com/bar
>>   B. server returns content (which will be http://foo.com/bar/index.html)
>>   C. client sees the content in browser
>>   D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com (rather than http://foo.com/bar/index.html)
>>
>
> As someone else indicated previously, this is a standard feature of
> mod_proxy.

Yes. However, AFAICT the ProxyPass cannot be given conditions as with RewriteRule. So if I have 

ServerName foo.com
ServerAlias dodo.foo.com

then the ProxyPass/Reverse will be applied to requests to either domains, which is not what I want (requests to foo.com should be processed as usual as there are other web apps served from there).

>> 2. Client clicks on a link that is on the page just received:
>>   A. the href will be, say, http://foo.com/bar/someotherpage.html
>>   B. server returns content
>>   C. client sees the content in browser
>>   D. AND the client's browser shows the URL (in Location text field) as being 
>>      http://dodo.foo.com/someotherpage.html (rather than 
>>      http://foo.com/bar/someotherpage.html)
>
> So I will rectify A above as follows :
>
>   A. the href will be http://dodo.foo.com/someotherpage.html

You're right, the href is actually "/someotherpage.html" so it will be as you say. 

> And that will work, because of the Proxy rules above (he will get the
> content of the file "http://foo.com/bar/someotherpage.html" )

In order to apply the proxying just for dodo.foo.com only, I use a rewrite rule. Here is what I have so far, seems to work completely: 

RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^/bar/(.*)               /$1    [R,L]

RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [P]

The [R,L] of first rule causes a redirect to client and the rule processing ends so client will just make a new request with the /bar/ stripped out, AND client browser will show the redirected URL. The [P] in second rule will cause proxying, but only for requests to dodo.foo.com, so client will NOT see that foo.com/bar is really the URL used. Time will tell if there are any corner cases that this doesn't cover. But boy, that rewrite module is powerful stuff!

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


Re: [users@httpd] best way to modify a URL

Posted by André Warnier <aw...@ice-sa.com>.
Much, much better, and really clear this time.

Oliver Schoenborn wrote:
> Sorry I didn't notice the html format, I'm amazed that some people were able to understand my question!
(only the smart ones)
  Hopefully it works now. Here is what I am trying to do, 2 separate cases:
> 
> 1. Client goes to http://dodo.foo.com: 
>   A. server changes this to http://foo.com/bar
>   B. server returns content (which will be http://foo.com/bar/index.html)
>   C. client sees the content in browser
>   D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com (rather than http://foo.com/bar/index.html)
> 

As someone else indicated previously, this is a standard feature of 
mod_proxy.
First, let's assume for a moment that "dodo.foo.com" and "foo.com" are 
really two different machines, with each its own Apache on it.

If you want to use mod_proxy, use ProxyPass to forward the call to the 
backend server.

ProxyPass / http://foo.com/bar/

The client sees only the front-end server, so he should never see the 
URL of the back-end.
However, there are exceptions :

a) if the back-end server itself sends a re-direct response (to the 
front-end server, but passed by the front-end server back to the 
client), then normally that re-direct response will refer to the 
back-end server (foo.com).
But luckily, that's what the proxyPassReverse directive is for, to 
correct that situation.
So, if you do :

ProxyPass / http://foo.com/bar/
ProxyPassReverse / http://foo.com.bar/

that would work.
(However, this is all a bit silly, because it means that you have one 
front-end system that does nothing else than passing everything to the 
back-end and back; so why have a front-end ?)

and b) for links inside of html pages. That is your case below.


> 2. Client clicks on a link that is on the page just received:
>   A. the href will be, say, http://foo.com/bar/someotherpage.html
>   B. server returns content
>   C. client sees the content in browser
>   D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com/someotherpage.html (rather than http://foo.com/bar/someotherpage.html)
> 

(First note that what you want above is not really possible. If the link 
in the page that the client gets is really 
"http://foo.com/bar/someotherpage.html", then that is what the client 
will see in the URL bar after he clicks on it). (Unless you want to have 
"foo.bar" redirect to "dodo.foo.bar" via a redirect response, but there 
you are really getting complicated).
So I will rectify A above as follows :

 >   A. the href will be "http://dodo.foo.com/someotherpage.html"

The easiest way to do that, would be for all your pages to use only 
links without a hostname, like :
<a href="/someotherpage.html">go there</a>

If the broser got such a page via an original URL like 
"http://dodo.foo.com", and he gets a page that contains a link to
"/someotherpage.html", then the browser will continue to address the 
same server to get that page, like :
"http://dodo.foo.com/someotherpage.html"

And that will work, because of the Proxy rules above (he will get the 
content of the file "http://foo.com/bar/someotherpage.html" )

-------------

So now let's take the situation where "foo.com" and "dodo.foo.com" are 
really the same machine and the same Apache.
That is in fact easier.

First, you would have to define (in the DNS system), that "foo.com" and 
"dodo.foo.com" resolve to the same IP address, the one of your server.
That is the first indispensable step.

Then, you would make it so that your Apache server knows to answer to 
both these names.  That, you do simply with :

ServerName dodo.foo.com
ServerAlias foo.com

So now, whether the client addresses "http://dodo.foo.com" or 
"http://foo.com", he really comes to the same place.

Let's also say that the DocumentRoot is
DocumentRoot /var/www/foo.com/

and that there is a document called "index.html" there.

So when the client addresses "http://dodo.foo.com" OR "http://foo.com", 
he always gets the file /var/www/foo.com/index.html.

That is getting closer, but still not entirely what you want.
You want that when he asks for "http://dodo.foo.com", he would actually 
get the document that is located at

/var/www/foo.com/bar/index.html

For that, we need mod_rewrite and a a RewriteRule

RewriteRule "^/(.*)$" "/bar/$1"

So now when the client addresses "http://dodo.foo.com" OR 
"http://foo.com", he always gets the file /var/www/foo.com/bar/index.html.
(In fact,  no matter what URL he asks, he will always get a "/bar/" 
added in front.)

That's good, but still not correct maybe, because maybe you want that 
this only happens when the client asks for "http://dodo.foo.com", and 
NOT when he asks for "http://foo.com".
No problem, we can put a condition on the above Rewrite :

RewriteCond %{HTTP_HOST} "dodo.foo.com"
RewriteRule "^/(.*)$" "/bar/$1"

So now we *only* do this when he asks for "dodo.foo.com" and NOT when he 
asks for another server name (like "foo.com").

Ok for the idea ?
You can do a lot more of this stuff. You just have to be careful not to 
get in a loop.


Now, go read the docs for all those directives.


---------------------------------------------------------------------
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] best way to modify a URL

Posted by Oliver Schoenborn <sc...@cae.com>.
Sorry I didn't notice the html format, I'm amazed that some people were able to understand my question! Hopefully it works now. Here is what I am trying to do, 2 separate cases: 

1. Client goes to http://dodo.foo.com: 
  A. server changes this to http://foo.com/bar
  B. server returns content (which will be http://foo.com/bar/index.html)
  C. client sees the content in browser
  D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com (rather than http://foo.com/bar/index.html)

2. Client clicks on a link that is on the page just received:
  A. the href will be, say, http://foo.com/bar/someotherpage.html
  B. server returns content
  C. client sees the content in browser
  D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com/someotherpage.html (rather than http://foo.com/bar/someotherpage.html)

I have tried the following, based on Justin's rewrite rule suggestion: 

RewriteEngine on
RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [R]

This takes care of 1A to 1C but not 1D or 2. For 1D, the Location shows http://foo.com/bar/ rather than the original http://dodo.foo.com. The rewrite log shows the following lines when requesting http://dodo.foo.com:

192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (2) init rewrite engine with requested uri /
192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (2) rewrite '/' -> 'dodo.foo.com/'
192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (2) rewrite 'dodo.foo.com/' -> 'http://foo.com/bar/'
192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (2) explicitly forcing redirect with http://foo.com/bar/
192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (1) escaping http://foo.com/bar/ for redirect
192.168.2.1 - - [16/Dec/2009:16:24:50 --0500] [dodo.foo.com/sid#6b5148][rid#18b80b0/initial] (1) redirect to http://foo.com/bar/ [REDIRECT/302]

I think the problem for 1D might be the redirect. If so, any ideas how to remove that step? For #2, perhaps a redirect rule? 

Oliver



> -----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: December 15, 2009 5:59 PM
> To: users@httpd.apache.org
> Subject: Re: [users@httpd] best way to modify a URL
> 
> Oliver Schoenborn wrote:
> > I have a simple problem:   the URL root for a client website we are
> setting up is http://foo.com/bar/*, but our client wants access to be
> it via http://dodo.foo.com<http://qun.foo.com>/*, how would I set this
> up? I have used mod_proxy in the past for something similar but this
> doesn't seem to be applicable here. I think mod_rewrite could handle it
> but it is rather complicated to learn in short time, if there is a
> simpler way or an example somewhere a link would be greatly
> appreciated. Cheers,
> > Oliver
> >
> >
> Hi.
> Please post your messages to the list (and preferably any list) in
> plain
> text, not in html.
> As it is, your question is not really understandable.  There are 3
> different hostnames mentioned, and it is not very clear what you mean.
> A "URL root" (whatever that really means), certainly never ends in "*".
> Your problem may be simple, but the way you explain it does not make it
> simple to understand.
> Try again ?
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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


---------------------------------------------------------------------
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] best way to modify a URL

Posted by André Warnier <aw...@ice-sa.com>.
Oliver Schoenborn wrote:
> I have a simple problem:   the URL root for a client website we are setting up is http://foo.com/bar/*, but our client wants access to be it via http://dodo.foo.com<http://qun.foo.com>/*, how would I set this up? I have used mod_proxy in the past for something similar but this doesn't seem to be applicable here. I think mod_rewrite could handle it but it is rather complicated to learn in short time, if there is a simpler way or an example somewhere a link would be greatly appreciated. Cheers,
> Oliver
> 
> 
Hi.
Please post your messages to the list (and preferably any list) in plain 
text, not in html.
As it is, your question is not really understandable.  There are 3 
different hostnames mentioned, and it is not very clear what you mean.
A "URL root" (whatever that really means), certainly never ends in "*".
Your problem may be simple, but the way you explain it does not make it 
simple to understand.
Try again ?




---------------------------------------------------------------------
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] best way to modify a URL

Posted by Norman Peelman <np...@cfl.rr.com>.
Oliver Schoenborn wrote:
>
> I have a simple problem: the URL root for a client website we are 
> setting up is http://foo.com/bar/*, but our client wants access to be 
> it via http://dodo.foo.com <http://qun.foo.com>/*, how would I set 
> this up? I have used mod_proxy in the past for something similar but 
> this doesn’t seem to be applicable here. I think mod_rewrite could 
> handle it but it is rather complicated to learn in short time, if 
> there is a simpler way or an example somewhere a link would be greatly 
> appreciated. Cheers,
>
> Oliver
>

In your virtualhost add the line:

<VirtualHost>
ServerName foo.com
ServerAlias dodo.foo.com
...
...
</VirtualHost>

but you need to ensure that dodo.foo.com is also registered. Usually you 
can do this through the same account as foo.com.


-- 
Norman Registered Linux user #461062 -Have you been to www.apache.org yet?-

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