I have a nice restlet application whose component attaches the following:
cmp.getDefaultHost().attach("/mycmd",ProcessReq.class);
And when the request URL is http: //<my-host>/mycmd/, the ProcessReq class returns an index.html that has links to other pages. These pages are in the same directory as index.html, and are referenced in my index.html as relative pages like in the example below:
<a href="otherpage.html">Other Page</a>
What I am finding, however, is that users tend to expect to use a URL without the trailing "/", for example: http: //<my-host>/mycmd . Unfortunately, when they do that, all links to the relative pages get screwed up.
When you use http: //<my-host>/mycmd/ to display index.html, then click on the "Other Page" link, the browser (correctly) goes to http: //<my-host>/mycmd/otherhost.html. Unfortunately, when you do http: //<my-host>/mycmd (without the trailing slash), the link to Other Page sends the browser to http: //<my-host>/otherpage.html, which of course returns a 404 error.
I have searched the Internet and discovered that the Restlet libraries have been designed to require a trailing slash after the kinds of URLs I am doing by default. Requiring that, however, will drive my users crazy.
Is there some way to configure or manipulate the request (or response) so that I can send this type of URL request without requiring a trailing slash, and have the relative links in the returned page point to the correct place?
Someone please advise...
The solution I would recommend is to automatically redirect the client browser to the URI with a slash if the user forgets to type it. Therefore, you relative URIs will stay simple.
Otherwise, you need to add the directory name again to each relative URI such as "mycmd/otherhost.html"