views:

475

answers:

2

How to redirect www.foo.com/bar to www.foo.com:8080 without "really" changing the url in the url bar?

So I want www.foo.com/bar (+ possible GET parameters / subfolders) to be shown always in the url bar.

Can this be done with mod_rewrite?

+4  A: 

You need a proxy (mod_proxy) to do this. Here is an example with mod_rewrite’s RewriteRule:

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
Gumbo
This will work but if the goal is to keep the client from connecting on port 80 it does no good.
Spencer Ruport
@Spencer Ruport: Fixed it.
Gumbo
True but I'm not sure what good this would do. Port 80 would still be blocked and this wouldn't circumvent any firewalls since the client packets would still be going out on port 80.
Spencer Ruport
I think he just wants to map the port 80 internally to port 8080.
Gumbo
perhaps. guess we'll just have to see what he says.
Spencer Ruport
Yes this is what I wanted but it does not seem to work completely. My images are missing from the web page. I use relative paths to those so does this proxy somehow mess up the relative pahts? How can I fix it?
No, the requested paths are passed along just as they come in. Are those files on the hidden server as well?
Gumbo
They are working if I go straight to www.foo.com:8080 but not throught the proxy (if I go to www.foo.com/bar or any subpage).
Here is my rewrite:RewriteCond %{SERVER_PORT} ^80$RewriteRule ^bar(.*?)$ http://%{SERVER_NAME}:8080/$1 [P]
And your image URL paths do match this pattern?
Gumbo
They are in relative path so I guess the relative path somehow gets messed up. I do not know why
Have you checked what URLs your browser requests? Either inside your browser or in the server access log?
Gumbo
[29/Apr/2009:09:11:03 +0300] "GET /images/logo/confluence_16.png HTTP/1.1" 404 227 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fi; rv:1.9.0.9) Gecko/2009040821 Firefox/3.0.9"
Well there it is: `^bar(.*?)$` doesn’t match `images/logo/confluence_16.png`. You have to adjust your pattern. Have you tried my suggestion?
Gumbo
Yes, it did not work either
+1  A: 

No it cant. The :8080 tells the browser what port to connect to the server on. If it's not present it assumes the default for whatever protocol prefix you have (http = 80, https = 443, ftp = 21 etc.)

Spencer Ruport