Hello there, I am trying to develop a web site and I am asking this:

Let's say that I own www.mydomain.com. Now if I type www.mydomain.com/whatever I want this site to be linked to www.mydomain.com and pass the string "whatever" as a parameter. So If I type www.mydomain.com/john the website should say "Hello john" and so on.
(Note: I don't want to use www.mydomain.com/?name=john)

Is there any way of doing this?

Recommended Answers

All 4 Replies

An alias in your web server configuration. This is a web server question, nothing at all to do with Java. See the documentation for your web server.

Edit: I.E. your "alias" will change "www.mydomain.com/john" to "www.mydomain.com/someservlet?someparam=john" and this can, normally, be done with wildcard expressions so you would not need to add every possibility.

So should I configure it from the domain name configuration (the site I bought the domain) or the web hosting configuration?

Are you directly serving pages via Tomcat or using some sort of webserver as front end (e.g. Apache web server, Nginx etc.)?

If you are using Apache, use something along the lines of mod_rewrite for Apache. I've never personally used it but heard that it can do wonders when it comes to manipulating URL's. I'm sure something similar exists for Nginx. If you are using a pure servlet front end, you might want to look into the UrlRewriteFilter. Please refer the appropriate documentation and relevant forum for finer configuration details or for help in getting started with the same.

Some might find this a bit klugy (and maybe it is), but I've accomplished this by setting up a custom 404 page to go to a jsp page. Then that jsp page can grab the requested url string and parse it out and forward (NOT redirect) as you see fit. Works pretty nicely for me.

Just don't forget to change the header back to 200 before you redirect. Also, make sure you use a forward (server side) and not a redirect (client side).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.