I wonder if this is a mistake, but right now I'm using GET for all my search URLs. The reason is that with GET Url the users can simple copy the link on the address bar and share or save easily. It seems like Google for example also uses GET Url (form).
Since it's a search form with filters, sorters and such the length of the generated URL can be unpredictable. I'm worried about the edge cases where the URL may exceed the length limit. On possible solution is to actually POST the data, then generate a unique hash based on that data, then use that has as the URL for the search. This solution does require saving the actual form data to database for example, then re-querying it on every search request which seems to be wasteful.
I wonder if there is any other way I haven't thought of yet?
Edit: I would like to say thank to all your answers here, they helped alot. I will summarize below what I did to solve this, hope it helps someone else:
There are several things that you can do to avoid URLs that are too long: If using dynamic URLs with URL parameters, use server-side URL rewrites to convert them into static, human-readable URLs. Try to minimize the number of parameters in the URL whenever possible.
Ever wonder why these URL are so long? The answer is simple: tracking codes. Tracking codes are strings of text added to the end of a URL that let you track the source of a click.
In short— the length of a URL could affect the appearance of search snippets, but does not affect search rankings. “This does not affect ranking. It's purely a matter of which URL is shown in search. So, to sum up, when it comes to search rankings, neither the URL length nor the number of slashes matter.
First of all, according to this Stack Overflow answer, you're fine up until 2000 characters1.
Once you hit that limit, if you want to keep your URLs shareable, you have a couple of choices I can see:
Let's consider the relative merits of these approaches.
In favour of hashing...
hash
, whereas it's less obvious what tools to use for the compression approach.In favour of compression...
Some of these factors may be irrelevant to you, depending upon your circumstances; I leave it to you to weigh up your priorities.
If you want to go the compression route, I don't know what tool to recommend to you. How to compress URL parameters may be a good place to start looking. Perhaps also consider https://github.com/pieroxy/lz-string to compress with https://github.com/nullpunkt/lz-string-php to decompress.
1 Note that a 2000 character URL is quite long. Are your URLs really this long?
https://www.google.com/search?as_q=you+have+to+write+a+really+really+long+search+to+get+to+2000+characters.+like+seriously%2C+you+have+no+idea+how+long+it+has+to+be&as_epq=2000+characters+is+absolutely+freaking+enormous.+You+can+fit+sooooooooooooooooooooooooooooooooo+much+data+into+2000+characters.+My+hands+are+getting+tired+typing+this+many+characters.+I+didn%27t+even+realise+how+long+it+was+going+to+take+to+type+them+all.&as_oq=Argh!+So+many+characters.+I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.+I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.I%27m+bored+now%2C+so+I%27ll+just+copy+and+paste.&as_eq=It+has+to+be+freaking+enormously+freaking+enormous&as_nlo=123&as_nhi=456&lr=lang_hu&cr=countryAD&as_qdr=m&as_sitesearch=stackoverflow.com&as_occt=title&safe=active&tbs=rl%3A1%2Crls%3A0&as_filetype=xls&as_rights=(cc_publicdomain%7Ccc_attribute%7Ccc_sharealike%7Ccc_nonderived).-(cc_noncommercial)&gws_rd=ssl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With