# URL Redirect Problems

**URL:** <https://www.ruby-forum.com/t/url-redirect-problems/198985>\
**Category:** NGINX\
**Created:** [November 11, 2010, 10:51pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985 "2010-11-11T22:51:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 11, 2010, 10:51pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/1 "2010-11-11T22:51:57Z")

</div>

Hello everyone,

I’m having problems attempting to redirect to another website. My  
objective here is when I visit “Site A” and click on a link, it will  
take me to another site on the same server, “Site B”. The URL has to  
look like that you’re still on “Site A” while displaying content from  
“Site B”. This is what my vhost.conf looks like right now.

```auto
server {
  listen *:80;
  charset utf-8;
  #server_name vbox.proxy.mysite.com;

  access_log /var/log/nginx/mysite.proxy.access.log;
  error_log /var/log/nginx/mysite.proxy.error.log error;

  root /home/webuser/webroots/mysite/utilities;

  location /tango {
      rewrite ^ http://vbox.bravo.mysites.com permanent;
  }
}
```

I’d go to “[vbox.proxy.mysite.com/tango](http://vbox.proxy.mysite.com/tango)” and I’ll be redirected to  
“[http://vbox.bravo.mysites.com](http://vbox.bravo.mysites.com)”, which is great in the sense that the  
content is displayed and I’m able to navigate the site normally. Any  
advice?

Posted at Nginx Forum:

> **[URL Redirect Problems](https://forum.nginx.org/read.php?2,149946,149946#msg-149946)**
>
> Hello everyone, I'm having problems attempting to redirect to another website. My objective here is when I visit "Site A" and click on a link, it will take me to another site on the same server, "Site B". The URL has to look like...

---

<div class="post-metadata">

**Author:** ![fwKilo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fwKilo](https://www.ruby-forum.com/u/fwKilo)\
**Post date:** [November 12, 2010, 8:34am UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/2 "2010-11-12T08:34:35Z")

</div>

Try this:

```auto
location /tango {
    rewrite ^(.*)$ http://nginx.org/ permanent;
}
```

Posted at Nginx Forum:

> **[Re: URL Redirect Problems](https://forum.nginx.org/read.php?2,149946,150049#msg-150049)**
>
> Hello everyone, I'm having problems attempting to redirect to another website. My objective here is when I visit "Site A" and click on a link, it will take me to another site on the same server, "Site B". The URL has to look like...

---

<div class="post-metadata">

**Author:** ![fwKilo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fwKilo](https://www.ruby-forum.com/u/fwKilo)\
**Post date:** [November 12, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/3 "2010-11-12T16:31:27Z")

</div>

It does the same thing as what I have. I’ve tried using proxy\_pass, but  
all it does is load up text and none of the images work.

Posted at Nginx Forum:

> **[Re: URL Redirect Problems](https://forum.nginx.org/read.php?2,149946,150151#msg-150151)**
>
> Hello everyone, I'm having problems attempting to redirect to another website. My objective here is when I visit "Site A" and click on a link, it will take me to another site on the same server, "Site B". The URL has to look like...

---

<div class="post-metadata">

**Author:** ![fwKilo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fwKilo](https://www.ruby-forum.com/u/fwKilo)\
**Post date:** [November 12, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/4 "2010-11-12T19:08:14Z")

</div>

Thank you for the advice, Francis. I do own both websites and they exist  
on the same server. I’ll try to clarify in what I’m trying to achieve. I  
want the URL to stay the same in the browser (which would be  
“[http://proxy.mysite.com/tango](http://proxy.mysite.com/tango)”) but display all of the content display  
from “[http://bravo.mysite.com](http://bravo.mysite.com)” and also be able to view other content on  
that page. There are frankly, way too many links for me to change in  
order to do this, so I thought I’d do it with nginx. So when a user  
visits “[http://proxy.mysite.com/tango](http://proxy.mysite.com/tango)”, they stay on that URL, but  
they’re actually on “[http://bravo.mysite.com/](http://bravo.mysite.com/)” and could surf that site  
normally.

Posted at Nginx Forum:

> **[Re: URL Redirect Problems](https://forum.nginx.org/read.php?2,149946,150198#msg-150198)**
>
> Hello everyone, I'm having problems attempting to redirect to another website. My objective here is when I visit "Site A" and click on a link, it will take me to another site on the same server, "Site B". The URL has to look like...

---

<div class="post-metadata">

**Author:** ![fwKilo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fwKilo](https://www.ruby-forum.com/u/fwKilo)\
**Post date:** [November 12, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/5 "2010-11-12T17:17:21Z")

</div>

On Fri, Nov 12, 2010 at 10:30:05AM -0500, fwKilo wrote:

Hi there,

> It does the same thing as what I have. I’ve tried using proxy\_pass, but  
> all it does is load up text and none of the images work.

As a reminder, that was:

```
    location /tango {
      rewrite ^ http://vbox.bravo.mysites.com permanent;
    }

```

If you want not to change the url in the browser bar, you must not issue  
a redirect (= an external rewrite).

Since the content is on a different server, you cannot just use an  
internal rewrite – you must use proxy\_pass.

If you control the [http://vbox.bravo.mysites.com](http://vbox.bravo.mysites.com) server, you will  
find it much easier if you can configure it to serve from the “/tango”  
url space (as in, [http://vbox.bravo.mysites.com/](http://vbox.bravo.mysites.com/) is empty apart from  
[http://vbox.bravo.mysites.com/tango/](http://vbox.bravo.mysites.com/tango/), which then has all the content  
below there) – otherwise, you will have to ensure that all links within  
the content are changed to include “/tango” as necessary, yourself.

(That’s presumably why the “none of the images work” – the browser  
requests /tango/file.html, which refers to /image.png; the browser then  
requests /image.png, which your proxying server does not proxy because  
it does not start with /tango.)

See the Fine Manual (on the wiki) for some other configuration  
directives  
that should help with the header rewriting, if necessary.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fwKilo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fwKilo](https://www.ruby-forum.com/u/fwKilo)\
**Post date:** [November 12, 2010, 7:56pm UTC](https://www.ruby-forum.com/t/url-redirect-problems/198985/6 "2010-11-12T19:56:30Z")

</div>

On Fri, Nov 12, 2010 at 01:06:51PM -0500, fwKilo wrote:

Hi there,

> Thank you for the advice, Francis. I do own both websites and they exist  
> on the same server. I’ll try to clarify in what I’m trying to achieve. I  
> want the URL to stay the same in the browser (which would be  
> “[http://proxy.mysite.com/tango](http://proxy.mysite.com/tango)”) but display all of the content display  
> from “[http://bravo.mysite.com](http://bravo.mysite.com)” and also be able to view other content on  
> that page.

Right.

So the browser asks for [http://proxy.mysite.com/tango/one.html](http://proxy.mysite.com/tango/one.html),  
and it gets the content from [http://bravo.mysite.com/one.html](http://bravo.mysite.com/one.html),  
which will link to and include other urls – which will be of  
the form “[http://bravo.mysite.com/one.png](http://bravo.mysite.com/one.png)” (in which case the  
browser will go directly to bravo, bypassing proxy); or of the form  
“/one.png” (in which case the browser will complete that url to  
“[http://proxy.mysite.com/one.png](http://proxy.mysite.com/one.png)”, which will probably fail to be served  
correctly); or of the form “one.png” or “./one.png” or something else  
that does not start with “/” (in which case the browser will complete  
the url to “[http://proxy.mysite.com/tango/one.png](http://proxy.mysite.com/tango/one.png)”, and the request  
should succeed).

So you _must_ ensure that every link that comes back from  
every page within “[http://bravo.mysite.com](http://bravo.mysite.com)” does not start with  
“[http://bravo.mysite.com](http://bravo.mysite.com)” and does not start with “/”. Or, they must be  
adjusted before they go to the browser.

> There are frankly, way too many links for me to change in  
> order to do this, so I thought I’d do it with nginx. So when a user  
> visits “[http://proxy.mysite.com/tango](http://proxy.mysite.com/tango)”, they stay on that URL, but  
> they’re actually on “[http://bravo.mysite.com/](http://bravo.mysite.com/)” and could surf that site  
> normally.

Yes, they can. But only if anything that the browser might  
interpret as a url to be completed, is correct according to the  
“[http://proxy.mysite.com/tango](http://proxy.mysite.com/tango)” url space by the time it reaches the  
browser.

This isn’t an nginx thing, it’s a (html) url-resolving thing.

You can filter the content in nginx on every request (although it’s  
unlikely to be easy to do right), or you can set it right once on the  
back-end.

(I assume it isn’t already all right on the back-end, because you report  
none of the images working. The html returned, and the web servers’  
logs should show you exactly why they aren’t working.)

Since the two sites are on the same server, you might be able to  
configure  
“proxy” to serve the “bravo” files directly. But that won’t help the  
“partial urls starting with /” thing.

Whichever you choose, good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
