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

RE: URL forwarding




> -----Original Message-----
> From: Sebastiaan [mailto:S.Breedveld@ITS.TUDelft.NL]
> Sent: Thursday, October 17, 2002 9:30 AM
> To: Price, Erik
> Cc: Sebastiaan; debian-user@lists.debian.org
> Subject: RE: URL forwarding

> heh, seems it does not support the 72 char linewrap either ;-)

No, it doesn't.  I'm at a new job and haven't had time to set up something respectable.

> > Also, I think that your RewriteBase directive should 
> specify an absolute
> > filesystem path, not a URI.  But I can't remember if it's 
> an absolute
> > filesystem path according to the server's filesystem or according to
> > document root.  So I would try:
> >
> > RewriteEngine On
> > RewriteBase /var/www/
> > RewriteRule ^(.+) /home/~mypage/ [R]
> >
> Doesn't work since ~mypage is not on my server, but on my 
> ISP's. In fact,
> I do not have any webpages on my server (too slow in upload), 
> so that is
> why I want to redirect them all.

I see, I didn't realize that you were trying to redirect to a different host.  Totally wrong of me, you're right that you need a URI in your RewriteRule.

> I found a link to the syntaxis of the rewrite module and I 
> got it working
> now! Add this to httpd.conf:
> 
> RewriteEngine on
> RewriteRule     ^/(.*)  http://www.myweb.com/~mypage/$1 [R]
> 
> and every query made to http://www.mydomain.com/whatever.ext is nicely
> redirected to http://www.myweb.com/~mypage/whatever.ext ;-)
> 
> 
> Most important step done, but now my next question:
> 
> After I typed http://www.mydomain.com/ in my browser, the URI 
> line also
> changes to http://www.myweb.com/~mypage/. Is there a trick so that the
> browser will keep displaying http://www.mydomain.com/ in the URI?

Unfortunately, I don't believe so.  This is possible if you are redirecting within your same server, basically you just do an internal rewrite of URL "x" to URL "y" and it just works.  That's actually the default of mod_rewrite.

However, we have overridden this default behavior by using the "[R]" option.  This option means "make an external redirect".  An anthropomorphization of this is "The server basically makes its own request for the specified URI by going out onto the internet and re-requesting with the new URI".

People use the [R] option when they specifically *want* to change the URI in the user's browser for whatever reason, since it doesn't interally rewrite the URI but externally does.  But to use mod_rewrite to redirect to another server, you *must* use [R] and do an external redirect (for obvious reasons).

So even if you had mod_rewrite on your server (www.myweb.com), if you were to try to do an external rewrite to (http://www.mydomain.com/) in an attempt to change the URI, this would also have the effect of making a request for that URI, which would create an endless loop since your server would then do an external rewrite for http://www.myweb.com/ .

NB I am not a mod_rewrite expert so someone should correctify me if I'm wrong.  That mod_rewrite guide on the Apache site has all kinds of black magic recipes, check in there to see if they have that.  (Not the mod_rewrite docs, but rather the page at http://httpd.apache.org/docs/misc/rewriteguide.html ).


Good luck,


Erik



Reply to: