0

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...

Factor Three
  • 2,094
  • 5
  • 35
  • 51

1 Answers1

1

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"

Jerome Louvel
  • 2,882
  • 18
  • 19
  • I actually tried something similar to what you suggested. From within the ServerResource I rewrote the URI, adding a slash to it. I was able to get to the right resource, but the relative URIs remained bad. If you are suggesting this, then I am clearly missing something. Are you suggesting that I put up a filter that does the redirect? What class/method should I use? Please elaborate. – Factor Three Feb 13 '13 at 13:40
  • I'm suggesting a client side redirect, so the browser can properly resolve the relative URIs. Then you can reuse Redirector or a custom Filter subclass. – Jerome Louvel Feb 14 '13 at 11:23
  • Thanks. That is the info I needed. I ended up creating a redirector with a mode of Redirector.MODE_CLIENT_PERMANENT, and that ended up making things work. I am uncertain of the difference between CLIENT_PERMANENT and CLIENT_TEMPORARY, though. Hopefully I can get more information about these. – Factor Three Feb 14 '13 at 12:53
  • This corresponds to the matching HTTP redirection statuses. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3 – Jerome Louvel Mar 26 '13 at 13:58