File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Resolving website name correctly in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Resolving website name correctly in Tomcat" Watch "Resolving website name correctly in Tomcat" New topic
Author

Resolving website name correctly in Tomcat

Deep Nair
Greenhorn

Joined: Dec 24, 2011
Posts: 13
My httpd file in Apache as proxy looks like below:


In Tomcat, my server.xml looks like below:


What's happening is that, in the browser, when I type www.mywebsitename.com, it shows only the Apache Welcome page but when I type www.mywebsitename.com/SYL, it shows the website welcome page.

What I want is that the www.mywebsitename.com should resolve to www.mywebsitename.com/SYL, so that the general user need not type /SYL in url. Please suggest.

Thanks,
Deepna
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Place an index.php file in your Apache's htdocs folder with the following content:
This way, when someone goes to the root, this index.php will be returned which tells the browser to go to SYL instead.
Note: you must have the PHP plugin enabled in Apache, and you may have to remove the existing index.html file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Deep Nair
Greenhorn

Joined: Dec 24, 2011
Posts: 13
Thanks Rob for the details, I'm using centos linux server, so i dont see the folder htdocs. How can i set it up in Centos ? Also im not using PHP, but JSP, is there a JSP plugin similar to PHP that needs to be enabled ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Are you running JSP directly in Apache, or in Tomcat? The PHP part should go in Apache, not Tomcat. It is a plugin that would need to be configured. Alternatively you can do it in HTML as well:
As for the location, you may also want to try /var/www/html. If that also does not exist, check httpd.conf and look for the value of the DocumentRoot directive.
Deep Nair
Greenhorn

Joined: Dec 24, 2011
Posts: 13
Thanks for the details, tried with the html option but could not make it work. In the httpd conf i can see the doc root set as var/www/html so created index.html and placed in html dir and restarted apache but didnt see any changes....not sure why its not working ...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

You should be able to forward the entire site over using this pair of statements:


However, the key word there is entire. That would force ALL URL requests for that host to be proxied to the SYL webapp in Tomcat. Which is OK, if that's the only webapp you intend to serve up. A variation of that idea would be to define the Proxy for an alternate virtual host, which would have a different domain name in the URL.

Mixing Tomcat and non-Tomcat requests on the same host and trying to share the same domain hostname can be tricky and usually involves extensive use of the mod_rewrite module. That's because you need clear rules as to what subsections of the URL would go where.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Deep Nair wrote:Thanks for the details, tried with the html option but could not make it work. In the httpd conf i can see the doc root set as var/www/html so created index.html and placed in html dir and restarted apache but didnt see any changes....not sure why its not working ...

Is there perhaps also an index.php in the same folder? If that's the case this is probably seen as the default document, and served instead of the index.html. What happens if you go to www.mywebsitename.com/index.html?
Deep Nair
Greenhorn

Joined: Dec 24, 2011
Posts: 13
Is there perhaps also an index.php in the same folder?

No there is no index.php in the same folder.

Also one more thing i have noticed is in IE if i type www.mywebsitename.com it resolves to the www.mywebsitename.com/SYL so its working in IE, but in Firefox its not working, in Firefox its still shows the Apache home page. So the index.html that you gave me earlier, does that need to be changed for Firefox compatibility ?

What happens if you go to www.mywebsitename.com/index.html?

I tried this in Firefox and its resolving to www.mywebsitename.com/SYL properly.... so not sure where the issue is.

Thanks,
deepna
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Perhaps Firefox still has an old version in its cache. Clear the cache (Options, Advanced, Network tab, Clear Now), then try again.
Deep Nair
Greenhorn

Joined: Dec 24, 2011
Posts: 13
Thanks Rob for your inputs !! yes clearing cache solved the issue...

Thanks,
**
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Resolving website name correctly in Tomcat
 
Similar Threads
Tomcat 7 digest authentication problem
Tomcat + Apache configuration servlet access problem
Sending an HTTP request from behind Apache
mapping external url to internal url
connecting Apache and Mongrel