So basically I have made a webapp with the following url www.foo.com/foo
(when deployed locally, my app has the following url localhost:8080/foo/
). However, I would like to use www.foo.com
instead. How can I go about doing this? Thanks! I have an apache2 web server and tomcat 7.

- 4,824
- 13
- 51
- 88
-
1Why? If you assign www.foo.com to localhost, you won't be able to reach the real www.foo.com anymore. If your app code is dependent on this URL, then you did something wrong. – JB Nizet Dec 26 '12 at 18:23
2 Answers
This is nothing to do with Spring, Apache, or Tomcat. It's all about name resolution, and it's done by lower-level things in the OS. You can force www.foo.com to resolve to your local machine by modifying the localhost line in your hosts file so it looks something like:
127.0.0.1 localhost www.foo.com
On Linux, that's in /etc/hosts
. On Windows, you'll find it at C:\Windows\System32\drivers\etc\hosts
(thanks to @JBNizet for supplying this). Note that if you do this, though, you'll no longer be able to get to the real www.foo.com because it'll always resolve to your local machine.
If you're trying to do this because your app internally references "www.foo.com" and needs to have it resolve correctly in order to work, then you're trying to solve that problem in the wrong way. You should pull those values out into some kind of external configuration so they can be set appropriately to the environment where the app is running.
Update: If this just about deploying to the root context of tomcat, that's been answered several times, like in Tomcat 6: How to change the ROOT application.

- 1
- 1

- 126,015
- 21
- 180
- 199
-
thanks ryan. i guess what im trying to do is to deploy my app, but i want to access it using www.foo.com. right now, i have to use www.foo.com/myapp to access it instead. ive looked at mod_proxy, and that works, but when my app redirects to the profile page, it appends foo to the url again. e.g., www.foo.com/foo/profile, instead of www.foo.com/profile – OckhamsRazor Dec 26 '12 at 18:35
-
ProxyPass / http://www.abc.com:8080/myApp/
ProxyPassReverse / http://www.abc.com:8080/myApp/
Or with
<VirtualHost X.X.X.X:80>
ServerName tomcatpage.yourdomain.com
ServerAlias tomcatpage.yourdomain.com
Redirect permanent / http://tomcatpage.yourdomain.com:8080/
</VirtualHost>
Read more about mod_proxy.

- 35,552
- 12
- 89
- 98
-
i actually tried this. however, if i login to my webapp, it goes to http://www.abc.com:8080/myApp/profile, instead of http://www.abc.com:8080/profile. – OckhamsRazor Dec 26 '12 at 18:32