tags:

views:

232

answers:

5

I think the URL length can only be 2000 or so characters long. Otherwise, it will choke some versions of IE. Is there any way to overcome this problem?

At first i was thinking about tinyurl, but tinyurl actually immediately redirects to the longer URL, so that probably will fail too.

Update:

I need such long URL because I need to be able for people to bookmark the URL or to send it to other people by email.

+5  A: 

That's what POST is for ;)

PQW
Agreed. Here are some "interesting" alternatives: http://www.boutell.com/newfaq/misc/urllength.html
RichardOD
+3  A: 

HTML POST is designed for transferring larger amounts of data. You should look at that.

John Nolan
+1  A: 

There's no realistic way to get around this - it's not a limitation in the specs or anything like that, but in IE itself and presumably how the URL is allocated (I believe the limit is actually 2083 characters by the way, for some reason).

Since IE needs the URL all in one go to send to the server, I can't think of any clever tricks that would enable you to work around it. Some options I considered were to send the query parameters via POST instead of GET (but this is often not interchangeable on the server side, and the clients will treat this differently in that the URL can't then appear in a hyperlink or be bookmarked or entered manually, and if the user wants to refresh they'll get the "send information again" warning, which makes sense since POST is meant to update information on the remote server, and it'll only work if it's the query string pushing it beyond the limit rather than some ungodly URL). Alternatively you could perhaps chunk up the URL, setting the overflow part in a cookie and then making the request to the stub of the URL, which is intelligent enough to pull the context out of the cookie and append it to the URL actually received. However this again complicates processing on the server, probably far too much to be used beyond a trivial application, and also still means you can't put that URL in hyperlinks or bookmarks or whatever, since an important part of it is client state.

Basically, everything else would involve rewriting the server to somehow piece together the extra information, and if you're able to do this then you should be able to simply change the URL scheme so that everything's below 2000 characters. So no - no real way around it.

(Though if you could use something like tinyurl to act as a proxy rather than issuing a browser redirect to the URL, that could work).

Andrzej Doyle
+3  A: 

For bookmarking reasons you could store a hash of the argument string in the databse as well as the argument list. That way when somone bookmarks something they get a bookmark with the hash in it and your internal software looks up the appropriate arguments and gets them.

You are in essence rolling your own tiny url.

If somone else wants to bookmark a page with the same arguments then the hash will be the same.

the only problem is that your table of hashes will grow quite big, and many of these "book marks" might never be used.

Omar Kooheji
why not use somesite.com/r.php?id=23456 or somesite.com/?id=23456 or even somesite.com/?23456
動靜能量
A hash of the parameters means that if somone comes up with the same parameters again then they will use the same bookmark.TO be honest though you are probably better off using mod rewrite and making your urls make sense and shortening them
Omar Kooheji
You can incorporate a GUID or a username into the hashed data.
Alex Feinman
+2  A: 

What do your urls look like? Maybe you could use gzip or md5 to shorten them, or store them in a database and put the id of the row in the url?

Adrian Mester