Forum Moderators: phranque
I am kinda new to apache so don't be to hard on me please.
I am trying to take a urlA and redirect it to urlB but still have urlA in the browser address bar.
I have the rewrite working but it shows the new ip address not urlA in the browser.
My code///////// which works but shows new ip address.
<VirtualHost *:80>
ServerName urlA.company.com
RewriteEngine On
# Force all requests for urlA to use ssl
RewriteRule (.*) [11.11.11.11:8443$1...] [R,L]
</VirtualHost>
Seems simple but it is driving me nutz!
TYVMIA : )
And if it were possible, you'd find that the SSL cert wouldn't work; The browser would throw 'insecure' and 'mixed content' warnings left and right.
You need to think about why you want to do this -- or think you need to do this, as the visitor has a right to know what site he or she is on.
If your goal is simply to serve 'shared' content from a different co-hosted filespace, then use mod_alias (Alias and AliasMatch) directives. Or if the files are or can be hosted in the same DocumentRoot filespace, then use an internal rewrite. Or you could use symlinks at the operating system level if you're on *nix. In all cases, you are doing a URL-to-filepath translation, not a URL-to-URL redirect; The URL doens't change, only the URL-to-filespace mapping changes. But the filespace needs to be in this machine, and you have to work within the access permissions model of this machine.
If neither of those approaches are applicable, then if you have control of both servers, you'll need to reverse-proxy requests from this server to that server. If you need valid server logs and stats on either or both of the sites, you'll need to set this server to send the Via and X-Forwarded-For HTTP headers to the other server, and you'll need to implement custom logging on the other server to 'sort out' the logs for this site and that site using the Via header, and if the requests are for this site, then log the X-Forwarded-For address instead of Remote_Addr in the logs on that server that apply to this site. (I've been careful with 'this' and 'that' here, and you'll need to be mindful of them too.)
In this case, all requests for this domain will pass through this server, get forwarded to that server, and will be logged on both. All requests for this site that are proxied to that server will appear to come from this server, and not from the original requesting client, which is why you need to configure the two headers I described.
Responses to these requests will then be sent from that server back to this server, and then from this server back to the client. Therefore, the client will experience some delay, depending on the speed of the servers and the network connection between them. If either server goes down, so does this site.
If you don't have control of both servers at the admin level, then you need a different plan, because the browser shows the URL it requests, and nothing server-side can change that.
Jim
So its impossible.. the way I am doing it.
I should say I had it setup and working very well before using proxypass and proxy pass reverse. But that only is working for http, when I redirect to a port running ssl it obviously breaks, and the site needs to use ssl.
My previous working config was as follows
<VirtualHost *:80>
ServerAdmin some@admin.com
ServerName www.urla.company.com
ServerAlias urla.company.com
#forward to tomcat
ProxyPass / [localhost:8080...]
ProxyPassReverse / [localhost:8080...]
ProxyPreserveHost On
ProxyPassReverseCookiePath / /
ErrorLog logs/firstdomain-error_log
CustomLog logs/firstdomain-access_log combined
</VirtualHost>
and the url in the browser remains urla inspite of where I redirect to. But it doesnt work when I try to use https ie [localhost:8443...]
-------------
I guess my main objective is complete by routing our pre existing http traffic hitting urla to the new secure location via rewriting, but the ugly ipaddress and port in the addressbar sickens me and if I can make it seem as it did previously it would be nice.
I will try some of the other suggested ways now and see if they work.
Thank you all : )
Jim
What exactly do you mean by this in terms of the URL you are requesting. You've used the term "redirect" above with reference to code which contains no redirects whatsoever... A proxy throughput is not a redirect. So that makes this statement ambiguous.
Is the problem occurring when you request your site via https, or when you attempt to proxy to the back-end using https?
If the former, the problem is that you need to move this virtualhost to the container used to listen to port 443, and replace it with a redirect from http to https.
Jim
I am sorry I keep saying redirect, I am little confused about how the proxy is not considered a redirect, but I think I am starting to understand the subtle difference. But how is the rewrite rule is not a redirect?
Previously I did have a configuration that I couldn't get to work where the virtualhost listing port was 443 and I was using https for the proxys. But this wasn't working correctly either. : ( I was getting page not found errors but I could access the site directly via the same address and protocol specified in the proxy directive, which is why I switched to the rewrite rule method which is working well except for the url in the address box.
Jim
Any sort of rewrite or pass-through sees the server accept a URL request and then silently fetch content from some place other than that suggested by the 'part part' of the original URL request.