homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite without changing url

 1:14 pm on Aug 23, 2013 (gmt 0)


I want to return another picture but the url most not be changed.

RewriteEngine on
RewriteRule ^/path/path/logo.gif$ http://someotherserver.com/p1/p2/anotherlogo.gif [P,L]

I always get a :
Not Found
The requested URL /p1/p2/anotherlogo.gif was not found on this server.

If I enter the url http://someotherserver.com/p1/p2/anotherlogo.gif I can see the picture exist

What am I missing?

[edited by: phranque at 8:41 pm (utc) on Aug 23, 2013]
[edit reason] unlinked url [/edit]



 9:28 pm on Aug 23, 2013 (gmt 0)

Is your mod_proxy enabled?
I think you do not need L flag as P assumes L


 1:06 am on Aug 24, 2013 (gmt 0)

RewriteRule ^/path

Is this rule located within a directory context-- either htaccess or a <Directory> envelope? If so you need to omit the leading / or the rule will always fail. If you're in the top level of the config file, you're fine as is.

I kinda think that if you don't have mod_proxy enabled, the RewriteRule with [P] flag will yield an error of some sort.

:: detour to verify that [P] takes an URL rather than a complete physical path ::

Test your rule by replacing [P] with [R,L]. If you get redirected appropriately, the rule is executing and you can start narrowing down the problem.


 9:50 pm on Aug 24, 2013 (gmt 0)

I have this config:
RewriteEngine on
RewriteRule ^/path/path/logo.gif$ http://someotherserver.com/p1/p2/anotherlogo.gif [P,L]

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all

ProxyPass / http://server.com/
ProxyPassReverse / http://server.com/


The proxy is working fine for url different than /path/path/logo.gif so the mod_proxy must be enabled. If I change [P,L] to [R,L] it is also redirect fine.

I found out if I set "ProxyPreserveHost Off" it's working fine. Why is this working?

[edited by: phranque at 2:58 am (utc) on Aug 25, 2013]
[edit reason] unlinked urls [/edit]


 11:24 pm on Aug 24, 2013 (gmt 0)

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost (intentionally de-linked to preserve fragment) with my emphasis

When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.

This option should normally be turned Off. It is mostly useful in special configurations like <further stuff in Hungarian snipped>.

Normally this is exactly what you don't want, which is why it's off by default. Why did you turn it on?

I found out if I set "ProxyPreserveHost Off" it's working fine.

In most situations you wouldn't need a ProxyPreserveHost line at all, unless you suspect your server administrator has turned it on and you need to ensure it's off.


 4:04 pm on Aug 25, 2013 (gmt 0)

I understand ProxyPreserveHost like this:

The client enter http://myserver.com
ProxyPreserveHost On - The proxied host will read 'myserver.com' from the Host header
ProxyPreserveHost Off - The proxied host will read 'internal-server.com' from the Host header (ProxyPass / http://internal-server.com/)

I have turn it on because I want the backend application to know which Host the client specified and not the host specified in the ProxyPass. Am also running Named-based Virtual hosting.

Or have I misunderstood something?

And why has ProxyPreserveHost On/Off influence on why RewriteRule [P] is working or not?

[edited by: phranque at 8:30 am (utc) on Aug 26, 2013]
[edit reason] unlinked urls [/edit]


 5:44 am on Aug 26, 2013 (gmt 0)

Or have I misunderstood something?

Yes, I think you have. The "preservehost" element refers to where the content actually comes from, not what the user's address bar says.

The whole point of a proxy is that the address bar doesn't reveal where you're getting the content; in effect it's a rewrite using a different host. If the request and the content both involved the same host, there would be no need for a proxy in the first place; that's a simple rewrite.

Disclaimer: I have never personally used this flag in my life.

:: looking vaguely around for someone who speaks Apache ::

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved