views:

141

answers:

3

I'm building an internal URL shortening website for my company. Since so few people will use it, we're letting people choose their own custom shortened URLs. So, for example, you could have the shortened URL:

http://goto/toms-projects

We thought it would be cool to offer, in addition to a regular redirect, the ability to leave the shortened URL in the address bar. One way to do this is with frames:

<frameset rows="100%,*" border="0">
  <frame src="http://some_really_long_url" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>

But this solution breaks links on the destination site (clicking one won't update the address bar).

What's the best way to accomplish this?

A: 

You could write a pass through script that reads the destination url, and passes the contents back. I doubt it would be robust though. I doubt any solution to this would be robust. What is the purpose of this? And what's wrong with the frame?

recursive
@recursive: What's wrong with the frame is mentioned by the OP: it "...breaks links on the destination site (clicking one won't update the address bar)."
Asaph
The purpose is that it's more visually pleasing to see http://goto/toms-projects in the address bar than http://some_really_long_url_with_special_characters
Horace Loeb
@Asaph: In what sense is that any more broken than the original concept?
recursive
@Horace Loeb Why are you worried about how visually pleasing the address bar is? It's intended to be functional. People are entirely fine with long URLs in it.
ceejayoz
@recursive: when the site is in a frame and the address bar remains constant as the user clicks around the site, individual pages are difficult to bookmark or email links to a friend.
Asaph
+1  A: 

Why not just do a server side include of the appropriate file/content instead of the redirect?

Asaph
Bad idea. What about relative URLs?
Kalmi
@Kalmi: I think this question was edited after I posted this answer. My answer made sense for the question as it was originally posted. In any case, I just posted another answer which is to use the html `<base>` tag to preserve the correct behavior of relative urls.
Asaph
+3  A: 

In order to preserve the original destination of relative links within the page, you could use the base tag.

<html>
    <head>
         ...
         <base href="/original/really/long/url/" />
         ...
    </head>
    <body>
          ...
          <a href="relative-url.html">a happy relative link</a>
          ...
    </body>
</html>
Asaph