• Post Reply Bookmark Topic Watch Topic
  • New Topic

Directing to the home page  RSS feed

 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

If an user enters in the url address as http://zoramsite.com/UsernameOrAnything

what I want is that the user will be directed to the home page of the site as
http://zoramsite.com

Where should I make changes in the application so as to succeed?

I think there is something to do with the config file of the HTTP server, but not sure how to do it.

Please Please Please advice,

Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what kind of server software you have running (Apache, servlet container, ...) and on whether the directory "UsernameOrAnything" exists or not.

Either way, it has nothing to do with web services, which is what this forum is about. Let us know what software you're working with, and we'll move it to a more appropriate forum.
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reply to:

That depends on what kind of server software you have running (Apache, servlet container, ...) and on whether the directory "UsernameOrAnything" exists or not.

Either way, it has nothing to do with web services, which is what this forum is about. Let us know what software you're working with, and we'll move it to a more appropriate forum.




Actually "UsernameOrAnything" is not a directory or other thing but simply a text that the user may enter in the url, which will redirect to the home page of the url. I am using Tomcat 5.5

eg: actual url is: http://www.zorampaul.com
but user enters: http://www.zorampaul.com/whateverHeWants
And this link directs to the http://www.zorampaul.com/home.jsp

Can you advice on this?


Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could configure an error page for 404 errors which redirects to the home page.
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide a better solution rather than that?
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zoram Paul:
Can you provide a better solution rather than that?


If you give a few details about why exactly you need this behaviour and what you want to achieve, someone could probably give you some suggestions.

But as of now, Ulf Dittmer's answer seems to be the best choice because you will have some directories and pages right? So you need to distinguish between those and these cases where the user types in invalid paths; in the former, you need to serve the resource while with the latter you want to redirect to the home page.

If you're not going to have anything but the homepage then you could use a catch-all url pattern (/*) mapped to your homepage.
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you give a few details about why exactly you need this behaviour and what you want to achieve, someone could probably give you some suggestions.

But as of now, Ulf Dittmer's answer seems to be the best choice because you will have some directories and pages right? So you need to distinguish between those and these cases where the user types in invalid paths; in the former, you need to serve the resource while with the latter you want to redirect to the home page.

If you're not going to have anything but the homepage then you could use a catch-all url pattern (/*) mapped to your homepage.




So that I can take out the last word from http://www.zorampaul.com/userwords
i.e, the word "userwords" from the http://www.zorampaul.com/userwords

And check out in the database the related word and redirects the user to an url by matching the "userwords" with that of a field in the database.
But for that operation to be done I need the home page. Thats why i have been asking this question how to redirect it to the home page.

Can you suggest now?

Thanks
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tarun said:
If you're not going to have anything but the homepage then you could use a catch-all url pattern (/*) mapped to your homepage.


Even if you have anything else you should explicitly map the urls to the servlets.


Spec says:
1. The container will try to find an exact match of the path of the request to the
path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done
by stepping down the path tree a directory at a time, using the �/� character as
a path separator. The longest match determines the servlet selected



Zoram said:
So that I can take out the last word from http://www.zorampaul.com/userwords
i.e, the word "userwords" from the http://www.zorampaul.com/userwords

And check out in the database the related word and redirects the user to an url by matching the "userwords" with that of a field in the database.
But for that operation to be done I need the home page. Thats why i have been asking this question how to redirect it to the home page.


Redirect to what? You have some key value pairs in db? Like username as key and a url as value? Why do you need to redirect to home page?
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amol Nayak:

Even if you have anything else you should explicitly map the urls to the servlets.


Isn't that what I said? You map the servlet to "/*" or "/", it'll become the default servlet for the application and will intercept all requests; from the looks of his app, he had only one servlet since he wasn't worried about other resources not being accessible.

Zoram, are trying to build something like TinyURL?
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun said:
If you're not going to have anything but the homepage then you could use a catch-all url pattern (/*) mapped to your homepage.


I found the statement bit incomplete as even if you have something other than homepage in the app you can use /* and use a more specific url pattern to map to different servlets as the spec says.
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amol Nayak:


I found the statement bit incomplete as even if you have something other than homepage in the app you can use /* and use a more specific url pattern to map to different servlets as the spec says.


That's true since an exact match takes priority over a wildcard match, right? I guess I wasn't very clear with what I was trying to get across
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!