Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule is redirecting when it shouldn't

Expected a proxy through-put instead

         

ntbgl

4:15 am on Feb 19, 2009 (gmt 0)

10+ Year Member



I'm trying to load content from a different domain in a flash document. According to Adobe's direction, I need to institute a workaround to prevent a security error. One of the workarounds it recommends is to use some kind of proxy to load content from the remote server onto the same server as the flash file. They provided some different types of code, but to me, it seems like a rewrite rule would make the most sense.

I thought to myself that I'll just setup a rewrite rule and have the flash file think its loading a file on the local server, but really the server will be pulling it from the remote one.

I added this line to my .htaccess file:

RewriteRule ^image/(.*\.jpg)$ http://www.example.com/$1 [nc]

I still get the errors in flash, and worse, if I try to access this file on my own server, for example, going to /image/test.jpg, the server is redirecting me to http://www.example.com/test.jpg.

But I'm not telling it to use a redirect. There' isn't anything like [r=301] in there!

What am I doing wrong?

Caterham

10:25 am on Feb 19, 2009 (gmt 0)

10+ Year Member



The P flag for proxy is missing. You need a reverse proxy if you'd like to fetch content from a different domain which is not in the scope of the current domain (e.g. in a subdirectory).

There' isn't anything like [r=301] in there!
But a fully-qualified domain which is not the current host, this implies an external redirection.
You may want to read

Apache manual [httpd.apache.org]:

Absolute URL
If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL.

ntbgl

12:27 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



Thank you for you reply.

I rewrote my statement to:

RewriteRule ^image/(.*\.jpg)$ http://www.example.com/$1 [P,NC]

I even put my flags in capital letters, and in the same order as used in the manuel, [httpd.apache.org...]

From reading your post it seemed like without the flag, it would automatically redirect because it was a different domain, and that I needed the P flag, but is there anything else that I need? Because my new flags don't seem to work.

Caterham

12:41 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



Order and case doesn't matter.

You should get errors if there's sthg. wrong.
403 if mod_proxy is n/a
500 if mod_proxy is available, but mod_proxy_http is not available (apache 2.1+).

From reading your post it seemed like without the flag, it would automatically redirect because it was a different domain

Yes.

jdMorgan

3:11 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I added this line to my .htaccess file

Unless you have other working RewriteRules already in that file, you will likely need to add either both of these lines above your rule, or at least add the second line. The only way to find out whether both are required is to test -- preferably with a very simple rule, such as a redirect from "foo.html" to google.com or similar.


Options +FollowSymLinks
RewriteEngine on

Jim

[edited by: jdMorgan at 3:17 pm (utc) on Feb. 19, 2009]