You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Robert L. Harris" <Ro...@rdlg.net> on 2002/01/11 17:45:16 UTC

Rewriting a URL

Still digging into this.  My httpd.conf has this:

    Redirect /site http://gonzo1.company.com
    RewriteEngine  on
    RewriteLog logs/site1.rewrite
    RewriteLogLevel 9
    RewriteRule ^.*gonzo.*company.com/(.*)         http://site1.company.com/$1 [L,R]


The theory would be to rewrite any outbound instance of "gonzo1" to "site1"
for the hostname.  I found the logging directive and see this in my logs:

[rharris@sslproxy01 httpd]$ tail -20f site1.rewrite 
10.10.117.230 - - [11/Jan/2002:16:42:00 -0700] [site1.company.com.com/sid#80b7788][rid#80ccfe0/initial] (2) init rewrite engine with requested uri /site
10.10.117.230 - - [11/Jan/2002:16:42:00 -0700] [site1.company.com.com/sid#80b7788][rid#80ccfe0/initial] (3) applying pattern '^.*gonzo.*company.com/(.*)' to uri '/site'
10.10.117.230 - - [11/Jan/2002:16:42:00 -0700] [site1.company.com.com/sid#80b7788][rid#80ccfe0/initial] (1) pass through /site


The first problem is that the url it's reading doesn't seem to have the
hostname.  Ummm, that's not a good thing.


:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.
> 
> NameVirtualHost *
> 
> <VirtualHost *>
> ServerName site1.company.com
> ProxyPass / http://gonzo1.company.com/
> ProxyPassReverse / http://gonzo1.company.com/
> </VirtualHost>
> 
> <VirtualHost *>
> ServerName site2.company.com
> ServerAlias site3.company.com
> DocumentRoot /var/www3/html
> </VirtualHost>


I owe ya a beer.  Only problem is the coders have a sub page that lists the
name of the internal server.  I may not have to worry about this.


:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.
Thus spake Joshua Slive (joshua@slive.ca):

> 
> > From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
> 
> > Here's my VHost block:
> >
> > NameVirtualHost site1.company.com
> 
> You appear not to have read the namevirtualhost documentation.  I'd start
> here:
> http://httpd.apache.org/docs/vhosts/name-based.html
> 

On my list for my weekend reading.  I'm still learning what all I have to learn.

> Again, this should be the IP address or "*", not site1.copmany.com.
> 
> >     ServerName          site1.company.com
> >     ServerAdmin         rharris@raindance.com
> >     DocumentRoot        /var/www1/html
> 
> Why do you have a DocumentRoot when no content is served from this site?

Originally there was going to be content in /var/www1/html and if you went to
/var/www1/html/site then it'd redirect ya.


> What you need is to proxy the content through site1.company.com.  That is,
> you need site1 to go grab the content from gonzo1 and return it to the
> client as if it came from site1.  To do this, you need to configure a
> "reverse proxy".  This requires mod_proxy to be included in the server.
> Then you can either use the ProxyPass and ProxyPassReverse directives (for
> simple cases) or the [P] flag to RewriteRule (for complicated cases).
> 
> Because I'm procrastinating, here is what I think you want:
> 
> NameVirtualHost *
> 
> <VirtualHost *>
> ServerName site1.company.com
> ProxyPass / http://gonzo1.company.com/
> ProxyPassReverse / http://gonzo1.company.com/
> </VirtualHost>
> 
> <VirtualHost *>
> ServerName site2.company.com
> ServerAlias site3.company.com
> DocumentRoot /var/www3/html
> </VirtualHost>

While waiting on a reply I stumbled accross mod_proxy and found some of
this.  Yours is still alot simpler than mine.

> 
> Before I go, a couple points:
> 
> 1. This is a quite complicated configuration where many things can go wrong.
> You need to spend some time to read the docs for each of these directives to
> make sure you understand everything.  Don't just copy some example (like the
> one above) and hope it works.

Right now I'm under a time constraint to show that the project will even come
close to working before I can get approval, etc.  This is a small peice of a
very large picture, but a very critical one.  If I can get this sucker humming
I'll have the time and resources to dig alot more.  I think your help has 
given what I need.

> 2. You make everyone's life more difficult by munging your config file.  Is
> the URL really so secret?  I bet I could find it out in 5 minutes if I
> wanted to.  This way, I had to make tons of guesses, rather than knowing
> exactly what was happening.

Not really "that" secret.  I'm testing on internal subdomains.  The server
name is actually considerably longer with 2 dns subdomains in the way.  It
was more of trying to keep it simple.


:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


RE: Rewriting a URL

Posted by Joshua Slive <jo...@slive.ca>.
> From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]

> Here's my VHost block:
>
> NameVirtualHost site1.company.com

You appear not to have read the namevirtualhost documentation.  I'd start
here:
http://httpd.apache.org/docs/vhosts/name-based.html

It will tell you that the NameVirtualHost directives takes an IP address (or
"*" for a recent version).  Assuming site1.company.com and site2.company.com
use the same IP address, you only need one NameVirtualHost line for both of
them.  If they aren't using the same IP address, you don't need
NameVirtualHost lines at all.

> <VirtualHost site1>

Again, this should be the IP address or "*", not site1.copmany.com.

>     ServerName          site1.company.com
>     ServerAdmin         rharris@raindance.com
>     DocumentRoot        /var/www1/html

Why do you have a DocumentRoot when no content is served from this site?

>     Redirect            /
> http://gonzo1.company.com

With this Redirect, eveything else is irrelevant.  All requests will get
redirected to gonzo1.company.com.

> [Fri Jan 11 17:29:26 2002] [warn] NameVirtualHost
> site3.company.com:80 has no VirtualHosts
>                                                            [  OK  ]
> but I think that's unrelated)

Probably unrelated, but shows you still need to do a little more reading
about name-virtual hosts.

>
>
> I hit the web page:
>
> http://site1.company.com
>
> It redirects and loads the page at:
>
> http://gonzo1.company.com  (an internal server firewalled out completely).
>
> This is working great so far, but when the page is loaded the URL in the
> location bar needs to read site1, not gonzo1.  If someone clicks
> the or bookmarks
> it they can't go back later as they can't actually reach gonzo1.

You can't use Redirects for this.  Redirects simply tell the client to go
fetch the page at a new location.  If that location isn't accessible to the
client because it is behind a firewall, this will never work.

What you need is to proxy the content through site1.company.com.  That is,
you need site1 to go grab the content from gonzo1 and return it to the
client as if it came from site1.  To do this, you need to configure a
"reverse proxy".  This requires mod_proxy to be included in the server.
Then you can either use the ProxyPass and ProxyPassReverse directives (for
simple cases) or the [P] flag to RewriteRule (for complicated cases).

Because I'm procrastinating, here is what I think you want:

NameVirtualHost *

<VirtualHost *>
ServerName site1.company.com
ProxyPass / http://gonzo1.company.com/
ProxyPassReverse / http://gonzo1.company.com/
</VirtualHost>

<VirtualHost *>
ServerName site2.company.com
ServerAlias site3.company.com
DocumentRoot /var/www3/html
</VirtualHost>

Before I go, a couple points:

1. This is a quite complicated configuration where many things can go wrong.
You need to spend some time to read the docs for each of these directives to
make sure you understand everything.  Don't just copy some example (like the
one above) and hope it works.

2. You make everyone's life more difficult by munging your config file.  Is
the URL really so secret?  I bet I could find it out in 5 minutes if I
wanted to.  This way, I had to make tons of guesses, rather than knowing
exactly what was happening.

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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.
First up, thanks, been banging my head on this for 2 days now. 

Here's my VHost block:

NameVirtualHost site1.company.com
<VirtualHost site1>
    ServerName          site1.company.com
    ServerAdmin         rharris@raindance.com
    DocumentRoot        /var/www1/html
    Redirect            /                               http://gonzo1.company.com
    RewriteEngine       on
    RewriteLog          logs/site1.rewrite
    RewriteLogLevel     9
    RewriteCond         %{HTTP_HOST} gonzo1.* [NC]
    RewriteRule         (.*) http://site1.company.com/$1 [L,R]
    ErrorLog            logs/site1
    CustomLog           logs/site1.custom common
</VirtualHost>

NameVirtualHost site2.company.com
<VirtualHost site2>
    ServerAdmin rharris@raindance.com
    DocumentRoot /var/www3/html
    ServerName site3.company.com
    ErrorLog logs/site3
    CustomLog logs/site3.custom common
</VirtualHost>

(on a slightly different note, when I restart apache I get this error:
Stopping httpd:                                            [  OK  ]
Starting httpd: 
[Fri Jan 11 17:29:26 2002] [warn] NameVirtualHost site3.company.com:80 has no VirtualHosts
                                                           [  OK  ]
but I think that's unrelated)


I hit the web page:  

http://site1.company.com

It redirects and loads the page at:

http://gonzo1.company.com  (an internal server firewalled out completely).

This is working great so far, but when the page is loaded the URL in the
location bar needs to read site1, not gonzo1.  If someone clicks the or bookmarks
it they can't go back later as they can't actually reach gonzo1.

Robert





Thus spake Joshua Slive (joshua@slive.ca):

> 
> 
> > From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
> > My URL returned after the page load is:
> >
> > http://gonzo1.company.com/somegarbage.html
> >
> >   and it needs to be
> >
> > http://site1.company.com/somegarbage.html
> >
> 
> Please show exactly what directives you are using, what URL you are using,
> and what you expect to happen.
> 
> 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@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


RE: Rewriting a URL

Posted by Joshua Slive <jo...@slive.ca>.

> From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
> My URL returned after the page load is:
>
> http://gonzo1.company.com/somegarbage.html
>
>   and it needs to be
>
> http://site1.company.com/somegarbage.html
>

Please show exactly what directives you are using, what URL you are using,
and what you expect to happen.

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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.

Ok, This looks good for the incoming stream.  I can see where it's trying to match:
10.10.117.230 - - [11/Jan/2002:17:04:12 -0700] [site1.company/sid#80b7788][rid#80cd320/initial] (2) init rewrite engine with requested uri /site
10.10.117.230 - - [11/Jan/2002:17:04:12 -0700] [site1.company/sid#80b7788][rid#80cd320/initial] (3) applying pattern '(.*)' to uri '/site'
10.10.117.230 - - [11/Jan/2002:17:04:12 -0700] [site1.company/sid#80b7788][rid#80cd320/initial] (4) RewriteCond: input='site1' pattern='gonzo1.company.com' => not-matched
10.10.117.230 - - [11/Jan/2002:17:04:12 -0700] [site1.company.com/sid#80b7788][rid#80cd320/initial] (1) pass through /site

It's seeing the intcoming request going to site1.company.com.  My redirect rule
kicks in pointing the request to go to gonzo1.company.com and it servers up
the data nicely.  The problem is that when the data is done loading and I look
at the URL returned, it's still pointing to gonzo.  The outbound url is not
being rewritten.  My URL returned after the page load is:

http://gonzo1.company.com/somegarbage.html  

  and it needs to be
 
http://site1.company.com/somegarbage.html




Thus spake Joshua Slive (joshua@slive.ca):

> 
> > From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
> 
> >     RewriteRule ^.*gonzo.*company.com/(.*)
> > http://site1.company.com/$1 [L,R]
> >
> >
> > The theory would be to rewrite any outbound instance of "gonzo1"
> > to "site1"
> > for the hostname.  I found the logging directive and see this in my logs:
> 
> > The first problem is that the url it's reading doesn't seem to have the
> > hostname.  Ummm, that's not a good thing.
> 
> That's right.  RewriteRule matches only on the part of the URL following the
> hostname and port.  What you want is something like (untested):
> 
> RewriteCond %{HTTP_HOST} gonzo.*company.com [NC]
> RewriteRule (.*) http://site1.company.com/$1 [L,R]
> 
> 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@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


RE: Rewriting a URL

Posted by Joshua Slive <jo...@slive.ca>.
> From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]

> 
> RewriteRule ^.*gonzo.*company.com/(.*)         
> http://site1.company.com/$1 [L,R]
> 
> 
> The [L,R]...  Where do those come from?  I haven't been able to find a 
> page explaining what they mean.  I've probably not gotten to that part of
> the manual yet though.
> 

See the "flags" section under:
http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteRule

They mean "Last" and "Redirect".

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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.
RewriteRule ^.*gonzo.*company.com/(.*)         http://site1.company.com/$1 [L,R]


The [L,R]...  Where do those come from?  I haven't been able to find a 
page explaining what they mean.  I've probably not gotten to that part of
the manual yet though.


Thus spake Joshua Slive (joshua@slive.ca):

> 
> > From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
>  
> > What are the letters in bracets?  
> 
> Huh?  Can you form that into an understandable question?
> 
> 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@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


RE: Rewriting a URL

Posted by Joshua Slive <jo...@slive.ca>.
> From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
 
> What are the letters in bracets?  

Huh?  Can you form that into an understandable question?

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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Rewriting a URL

Posted by "Robert L. Harris" <Ro...@rdlg.net>.
What are the letters in bracets?  


Thus spake Joshua Slive (joshua@slive.ca):

> 
> > From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]
> 
> >     RewriteRule ^.*gonzo.*company.com/(.*)
> > http://site1.company.com/$1 [L,R]
> >
> >
> > The theory would be to rewrite any outbound instance of "gonzo1"
> > to "site1"
> > for the hostname.  I found the logging directive and see this in my logs:
> 
> > The first problem is that the url it's reading doesn't seem to have the
> > hostname.  Ummm, that's not a good thing.
> 
> That's right.  RewriteRule matches only on the part of the URL following the
> hostname and port.  What you want is something like (untested):
> 
> RewriteCond %{HTTP_HOST} gonzo.*company.com [NC]
> RewriteRule (.*) http://site1.company.com/$1 [L,R]
> 
> 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@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


RE: Rewriting a URL

Posted by Joshua Slive <jo...@slive.ca>.
> From: Robert L. Harris [mailto:Robert.L.Harris@rdlg.net]

>     RewriteRule ^.*gonzo.*company.com/(.*)
> http://site1.company.com/$1 [L,R]
>
>
> The theory would be to rewrite any outbound instance of "gonzo1"
> to "site1"
> for the hostname.  I found the logging directive and see this in my logs:

> The first problem is that the url it's reading doesn't seem to have the
> hostname.  Ummm, that's not a good thing.

That's right.  RewriteRule matches only on the part of the URL following the
hostname and port.  What you want is something like (untested):

RewriteCond %{HTTP_HOST} gonzo.*company.com [NC]
RewriteRule (.*) http://site1.company.com/$1 [L,R]

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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org