Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: Ocean10000 & incrediBILL & phranque

Very stupid URL rewriting question

   
5:47 pm on Jan 23, 2014 (gmt 0)



Hi,

this is likely a FAQ, but I have not found the right answer here or at other places.

My setup:

- Tomcat listening at both http and ajp13 ports, serving dynamic content at http://example.com:8080/xyz/
- Apache frontending this tomcat via mod_jk, serving the dynamic content at http://example.com/xyz/

What I want:

Apache redirecting/proxying/aliasing (whatever) requests from http://example.com/abc/ to http://example.com/xyz/ but never-ever showing "/xyz" in the browser. This last part, hiding the "/xyz" seems to be tough ...

Thanks in advance
Martin

[edited by: Ocean10000 at 1:31 am (utc) on Jan 24, 2014]
[edit reason] Examplified [/edit]

10:26 pm on Jan 23, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Very stupid URL rewriting question

Oh, good, I like stupid questions. Sometimes I know the answer. Unless I'm the one with the question, in which case someone else has to explain it.

Looks like you missed the part about using "example.com". Now you see why.
Apache redirecting/proxying/aliasing (whatever)requests from http://example.com/abc/ to http://example.com/xyz/

Redirect, proxy and alias are all different things. If you're running your own server, it's crucial that you get a grip on the difference.

Crudely:
redirect = send an explicit message to the visitor, telling them to make a different request
proxy = roughly the same as a rewrite (internal) except that it involves two different hostnames. Whether it's host-internal or proxy, the visitor doesn't know
alias = server-internal directive saying "when I say 'example.com/blahblah/' I mean the directory 'oneplace/otherplace/righthere'"

but never-ever showing "/xyz" in the browser. This last part, hiding the "/xyz" seems to be tough ...

Is this happening within the same host? If so, it's a simple rewrite-- the kind you could do even in htaccess on shared hosting. Or are you talking about changing one aspect of aliasing?
7:30 pm on Jan 24, 2014 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



URLs are used out on the web, not inside a server. The browser makes a URL request either after a link is clicked or after a server returns a redirect response telling the browser to make a new request for a different URL.

The URL shown in the link the user clicks must point at the Apache server. When a request arrives at the Apache server, you will need to Proxy it through to the Tomcat server.
1:03 pm on Jan 26, 2014 (gmt 0)



Hi,

OK. It seems I made myself not clear when specifying my wishes. So, let us try again :-)

- I have a tomcat application "xyz" at "ajp://example.com:9999/xyz"
- I have an Apache 2.2 server at "http://example.com". That is on the same IP address, just to make that clear.

Case 1: I want to access the tomcat as "http://example.com/xyz". I can make that work using the following. Works fine:


ProxyPass /xyz ajp://localhost:9999/xyz
ProxyPassReverse /xyz http://localhost/xyz


Case 2: For some reason (if only to understand how), I want to access the application under the name "abc", but the tomcat installation has to stay at "xyz" (do not ask. It is so !). So I came up with the following:


ProxyPass /xyz ajp://localhost:9999/xyz
ProxyPassReverse /xyz http://localhost/xyz
<Directory /var/www/html>
RewriteEngine on
RewriteBase /
RewriteRule ^xyz/(.*)$ /abc/$1 [PT]
</Directory>


This works only partially. Content is served correctly, but when I enter "http://example.com/abc", the url in the browser is always rewritten as "http://example.com/xyz". This is what I do not want. I want it to stay "as entered".

Have I made myself more clear now?

Thanks
Martin
10:04 pm on Jan 26, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



the url in the browser is always rewritten as "http://example.com/xyz"

I knew I should have added "rewrite" to the "redirect : proxy : alias" set ;)

The URL is not getting rewritten. Only content can get rewritten. Your browser is putting in a fresh request for /xyz/ after the original request for /abc/. You should be able to see this in action from both sides: in your browser with an extension such as LiveHeaders, and in your logs showing two consecutive GET requests.

Next issue is that the rewrite seems to be set up backward. The rule
RewriteRule ^xyz/(.*)$ /abc/$1 [PT]

says "when there's a request for 'xyz', quietly serve content from 'abc'". Even if something went wrong and the rewrite turned into an external redirect, that wouldn't have any effect on requests for /abc/

:: detour to Apache docs because I have an ineradicable mental block on which is which between P and PT ::

Huh. I got it right, for once. But where else in your rules is /abc/? Did something get garbled when you exemplified?

If it helps, it's OK to use the real names of your subdirectories,* so long as it isn't something blindingly unique that would jump right up in searches.


* I say this with reluctance, as I vividly remember one forums visitor whose directories were all along the lines of
/blondes/tall/
/brunettes/overnight/
et cetera, only more so.
11:43 am on Jan 27, 2014 (gmt 0)



Yes - when doing the anonymization of the real work I fscked up and forgot the "abc" :-( This should have been written:

Case 2: For some reason (if only to understand how), I want to access the application under the name "abc", but the tomcat installation has to stay at "xyz" (do not ask. It is so !). So I came up with the following:


ProxyPass /abc ajp://localhost:9999/xyz
ProxyPassReverse /xyz http://localhost/abc
<Directory /var/www/html>
RewriteEngine on
RewriteBase /
RewriteRule ^xyz/(.*)$ /abc/$1 [PT]
</Directory>


So, my understanding is that the request for "xyz" can only come from the Tomcat. Thus user only knows about "abc". So how do I prevent the browser from displaying the "xyz" URLs? I had hoped that the rewrite rule would do that.

Thanks
Martin
5:02 pm on Jan 27, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



So, my understanding is that the request for "xyz" can only come from the Tomcat. Thus user only knows about "abc".

The good news is that I now understand the problem. The bad news is that your understanding is precisely backward :(

RewriteRule onething otherthing [L]


(or, in your case, [PT])

means: when the user asks for "onething", quietly serve content from "otherthing" while the address bar continues to say "onething". In your logs it will show as a single request for "onething" with no mention of "otherthing". (It will be visible in RewriteLogs, at least at some levels, but never in ordinary access logs.)

Turn the rule around.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month