tomcat redirect localhost

C

csteacy

Hello,
I'm working with an application that uses apache tomcat to serve the
website. I've installed the application and tomcat on a Windows 2003
server and everything is working fine. I do not have Apache or IIS
installed on the server. What I was trying to figure out is how to
make events.mydomain.xxx redirect to the localhost/myapp but without
the localhost part. For instance I want http://events.mydomain.xxx/ to
go to http://events.mydomain.xxx/myapp.

Any ideas how I might do this with apache tomcat would be very helpful
and appreciated. Thank you in advance.
 
M

Manish Pandit

Hi,

Based on what I understood, are you using absolute URLs in your app
instead of relative? If you were refering to root as / instead of
your.app.domain/ the app would have worked fine regardless of the
domain it is installed on. Is this the case?

-cheers,
Manish
 
C

csteacy

Manish said:
Hi,

Based on what I understood, are you using absolute URLs in your app
instead of relative? If you were refering to root as / instead of
your.app.domain/ the app would have worked fine regardless of the
domain it is installed on. Is this the case?

-cheers,
Manish

I'm a bit confused but I'll try to add more info. My app is installed
under the Tomcat root in the webapps/myapp/ directory. When I go to
http://localhost/myapp (on the server) it brings up the homepage. The
app is all preconfigured and I haven't touched tomcat to put in any
URLs or anything. I'm guessing upon install of the app that the folder
for it under tomcat root was created. I'm sorry I'm just not
knowledgable enough in this area. I hope that makes sense. Thanks
again for all the help.

Christy
 
B

bikemh

I think all you want is to write an index.jsp, and put that into
tomcat/webapps/ROOT

the JSP can use response.sendRedirect(string) from HttpServletResponse
(which is an implicit variable addressed in a JSP simply as-->
response)
 
M

Manish Pandit

If you want your application to show up as default tomcat app
(localhost instead of locahost/yourapp) , then go to the tomcat's
webapps folder, remove the contents of /ROOT, put your application in
there and give it a try after restarting tomcat. Again - I am not sure
if this is what you want.

-cheers,
Manish
 
B

bikemh

Manish said:
If you want your application to show up as default tomcat app
(localhost instead of locahost/yourapp) , then go to the tomcat's
webapps folder, remove the contents of /ROOT, put your application in
there and give it a try after restarting tomcat. Again - I am not sure
if this is what you want.

if she wanted to go that route, you could instead just edit server.xml
so that

<Host name="events.mydomain.xxx" appBase="">

<Context path="/" docBase="tomcat_home/webapps/myapp" />

</Host>

and thus redefine what is normally the ROOT webapp
 
C

csteacy

if she wanted to go that route, you could instead just edit server.xml
so that

<Host name="events.mydomain.xxx" appBase="">

<Context path="/" docBase="tomcat_home/webapps/myapp" />

</Host>

and thus redefine what is normally the ROOT webapp

I wanted to post back that this did work after a couple of trial and
error situations and remembering that I was working locally and not
publically yet so I had to use .local in the URL when testing instead
of the .com or .edu. Thank you again for all the advice and help.

-Christy
 
Joined
May 3, 2010
Messages
1
Reaction score
0
Close but not quite

In Tomcat 6 I used a relative path to make this work:

<Context path="/" docBase="myWebapp"/>
 
Joined
Dec 14, 2010
Messages
1
Reaction score
0
In order to do this the SEO-friendly and correct way so that Google does not identify you as having two different domains -- you need to use a specific HTTP 301 Redirect Code.

The only tricky way I found to do this in Tomcat was to use a Custom 404 Page implementation.

Add a new host entry in $CATALINA_BASE/server.xml as follows
Code:
            <Host name="newhost" debug="0" appBase="appbase" unpackWARs="true">
                <Context path="" docBase="docBase" debug="0">
                </Context>
            </Host>

Create a file $CATALINA_BASE/appbase/docBase/WEB-INF/web.xml as follows
Code:
<web-app>
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>
</web-app>

Create a file $CATALINA_BASE/appbase/docBase/404.jsp as follows
Code:
<%
response.setStatus(301);
response.setHeader( "Location", "newbaseURL" + (String)request.getAttribute("javax.servlet.forward.request_uri") );
response.setHeader( "Connection", "close" );
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Localhost 0
Eclipse - cannot create tomcat server 10
Tomcat Multi-Threading 23
Understanding VS2022 2
SSL Frontend(F5) - Apache - AJP - Tomcat howto 0
tomcat doubt 2
Universal system 2
Run TomCat on port 80? 10

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top