Forum Moderators: phranque
I am using mod_jk in Apache to host my website. On launching "http://www.abc.com" the home page of my application needs to be displayed and address bar should show "http://www.abc.com/index.html" but currently the address bar shows "http://www.example.com/MyApp/index.html" URL.
Can any of you please suggest a way to rewrite this URL as "http://www.example.com/index.html".
In short i want to hide the context(MyApp) in the URL. This context is name of the web application running on my Tomcat.
Please help.
Thanks
Kiran
[edited by: jdMorgan at 2:44 am (utc) on June 16, 2008]
[edit reason] example.com [/edit]
I suspect you've got your front-end site redirecting to Tomcat. The proper way to do this is to reverse-proxy the front-end requests to Tomcat. This method won't show the Tomcat application URLs in the browsers address bar.
We tend to throw around the terms "rewrite" and "redirect" far too loosely, treating them interchangeably, and this is one of the results. Take a look at the Apache mod_proxy documentation, and also at the [P] flag for Apache mod_rewrite's RewriteRule directive, particularly the information related to reverse proxies.
BTW, the common use of reverse-proxies for this kind of application is the origin of the terms "front-end" and "back-end."
Jim
Thanks for the information.
I have gone through "Reverse Proxy" and "RewriteRule" in the Apache documentation. Now I need some information on the RewriteRule.Below are my settings:-
Application on Tomcat OR Context : HelloWorld
Website : www.example.com
What should be the RewriteRule if i want to Redirect the hits from "www.helloworld.com" to "HelloWorld"?
I have used the below two lines and it is working fine but showing the Context:
RewriteRule ^$ http://www.example.com/HelloWorld/jsp/home.jsp [R]
RewriteRule ^/$ http://www.example.com/HelloWorld/jsp/home.jsp [R]
What i require is if a user types "http://www.example.com" in the address bar and hits Enter, the user should be directed to "HelloWorld" Tomcat application home page by showing "http://www.example.com/jsp/home.jsp" in the address bar.
Currently the URL shown in the address bar is "http://www.example.com/HelloWorld/jsp/home.jsp" ie the Tomcat context "HelloWorld" is shown in the URL. How can i hide the context?
Please help.
Thanks,
Kiran
[edited by: jdMorgan at 2:46 am (utc) on June 16, 2008]
[edit reason] example.com [/edit]
Thanks for the information.
I have gone through "Reverse Proxy" and "RewriteRule" in the Apache documentation. Now I need some information on the RewriteRule.Below are my settings:-
Application on Tomcat OR Context : HelloWorld
Website : www.example..com
What should be the RewriteRule if i want to Redirect the hits from "www.example.com" to "HelloWorld"?
I have used the below two lines and it is working fine but showing the Context:
RewriteRule ^$ http://www.example.com/HelloWorld/jsp/home.jsp [R]
RewriteRule ^/$ http://www.example.com/HelloWorld/jsp/home.jsp [R]
What i require is if a user types "http://www.example.com" in the address bar and hits Enter, the user should be directed to "HelloWorld" Tomcat application home page by showing "http://www.example.com/jsp/home.jsp" in the address bar.
Currently the URL shown in the address bar is "http://www.example.com/HelloWorld/jsp/home.jsp" ie the Tomcat context "HelloWorld" is shown in the URL. How can i hide the context?
Please help.
Thanks,
Kiran
[edited by: jdMorgan at 2:47 am (utc) on June 16, 2008]
[edit reason] example.com [/edit]
I'd like to help more, but I know nothing of Tomcat. See the [P] and [PT] flags for mod_rewrite's RewriteRule directive, and re-read the Apache mod_proxy module documentation and tutorials.
Jim
I tried the following. Please refer the "RewriteRule" section and "ProxyPass" section below.
----------------------------
<VirtualHost *:80>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" special
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
#ServerAlias server
ErrorLog logs/error11.log
CustomLog logs/11.log special
RewriteEngine On
RewriteRule ^/(.*.(asp[x]?¦exe¦cmd¦bat¦dll¦com¦cgi¦p(hp[3-6]?¦html¦l¦y¦erl))$¦cgi-bin) - [F]
RewriteRule ^$ /HelloWorld [R]
RewriteRule ^/$ /HelloWorld [R]
ProxyRequests Off
ProxyPass /HelloWorld http://example.com/jsp/home.jsp
#ProxyPassReverse /HelloWorld/ http://example.com/jsp/home.jsp
RewriteLog "logs/helloworld_rewrite.log"
RewriteLogLevel 1
# Deny direct access to WEB-INF
<LocationMatch ".*WEB-INF.*">
AllowOverride None
deny from all
</LocationMatch>
JkMount /*.jsp wrkr
JkMount /servlet/* wrkr
JkMount /* wrkr
</VirtualHost>
----------------------------
The above method shows "http://example.com/HelloWorld" in URL and displays a 404 error page(HTTP Status 404 - /jsp/home.jsp).
The above configuration didnt hide the context "HelloWorld".
Please help.
Thanks,
Kiran
[edited by: jdMorgan at 2:49 am (utc) on June 16, 2008]
[edit reason] example.com [/edit]
I refered the following link for the above configuration:
[apachetutor.org...]
Thanks,
Kiran
The first didnt worked and second worked, but it displayed "HelloWorld" in the address bar. And when i tried to do Reverse Proxy with the following, it gave me the same error(HTTP Status 404 - /jsp/home.jsp).
ProxyRequests Off
ProxyPass /HelloWorld [helloworld.com...]
#ProxyPassReverse /HelloWorld/ [helloworld.com...]
Please help.
Thanks,
Kiran
If a simple internal rewrite as I posted above seems to change the client address bar, then that indicates that a subsequent RewriteRule (mod_rewrite), Redirect or RedirectMatch directive (mod_alias), or a script is forcing an external redirect, and thereby 'exposing' the previously-completed internal rewrite to the client. You'll have to find and fix that mechanism.
Jim