Let's talk about short links

Let's talk about short links

Introduction

I am working on a promotion system recently, and I would like to share the problem of long and short links involved in it. The promotion method is mainly to send greetings to customers via SMS and push promotional links (not advertisements), but the links are really too long. Not to mention the problem of SMS being charged by word count, I just want to delete them immediately after seeing them. So the organization arranged to study how to make the links shorter and more concise. . .

About long and short links

  • Long link: As the name suggests, it is the complete URL address of a web page. Click it to jump to the web page and browse the content.
  • Short link: It is to convert a long link into a shorter URL address after processing. For example, https://sourl.cn/upNbxj is the result after processing the long link https://blog.csdn.net/qq_39486758/article/details/126602389.
  • Compared with long links, short links are shorter and easier to deal with problems such as character length restrictions on some third-party platforms. Of course, for the editor, it can save a lot of SMS fees. Whether you can "get promoted and make money" depends on it~~

Long and short link principle

  • When we enter the short link on the website, DNS will resolve the link's IP address (i.e. the short link server), and then DNS forwards the request (HTTP GET) to the short link server, and exchanges the short link code for the corresponding full URL address. Finally, the short link server redirects to the full URL address through the request (HTTP 301), and the resolution is completed. You can refer to the timing diagram:

Note: Short links can redirect to long links using 301 (permanent redirection) or 302 (temporary redirection). The difference lies in the management of resources. 301 will permanently remove the old resources and replace them with redirected new resources; while 302 will still retain the old resources, but only redirect them to the new resources. No replacement will occur and the new resources will not be saved.

Demo Case

  • Free online tools:

Webmaster's Home: https://tool.chinaz.com/tools/dwz.aspx, you need to register to use it. After all, it's free, so you still have to respect it~~

Short URL: https://www.dwz.lc/, which provides very complete functions such as setting validity period and access password, and is easy to use

  • Self-developed short link service: Due to the uncertainty of open source projects, we have to build a short link service to meet the needs of use. First, it is easy to maintain, and second, it can be flexibly expanded. Next, we will analyze it in combination with the code.

First, there is the algorithm tool class for generating short link codes. The algorithm is not fixed, and you can use other algorithms to generate according to your own habits or work requirements. The most important thing is to ensure the uniqueness of the short link code. Then there is the relationship mapping for maintaining short links. Here, the editor uses a collection variable. It is recommended to use a database such as MySQL to persist the relationship data to avoid data loss and access failure.

 /**
* Decode redirection
*
* @param url the encoding of the original link
* @return redirect
*/
@GetMapping("/redirect/{url}")
public ModelAndView redirect(@PathVariable String url) {
long id = BasetUtil.encode62to10(smartUrl);
String originUrl = urlMap.get(id);
RedirectView redirectView=new RedirectView(originUrl);
// 301 permanent redirection to avoid network hijacking
redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
return new ModelAndView(redirectView);
}

Simulation operation process: Start the short link service locally, then start a business service as a long link service, generate a short link from the long link, then access the short link and successfully jump to the long link address. Demonstration results

Summarize

The above is all the content shared in this article. Of course, there is more than one way to implement it. Friends who have ideas can send private messages to discuss.

<<:  Report: Global 5G mobile data traffic is growing explosively

>>:  Ministry of Industry and Information Technology: my country's fiber optic transformation has been fully completed, 4G network covers urban and rural areas, and 5G network is accelerating development

Recommend

5G lacks "soul"? Advanced technology is coming

Judging from the current situation, 5.5G technolo...

Free VPS, Free VPS Merchants with $50-100, Free Trial VPS

The tribe mainly shares cheap VPS hosts. Although...

Interviewer: What process will be executed after entering the URL?

After entering the URL in the browser, it will pe...

5G will soon be available to ordinary people

Currently, 5G has become a hot topic in the indus...

Three approaches to Bluetooth low energy development

Ask any IoT vendor what makes their product excit...

HTTP 2.0 protocol interview questions that will make the interviewer tremble

Http protocol is easy to use for programmers with...

When WiFi6 collides with 5G, is it a crisis or a business opportunity?

September 16, 2019 WiFi Alliance announces WiFi6 ...

Guava RateLimiter: A practical guide to efficient flow control

background With the rapid development of the Inte...

OlinkCloud: $5.6/month KVM-1GB/10G SSD/500GB/San Jose

Tribe shared the news about Olink.Cloud in Novemb...

What is cloud network?

The future of cloud is bright. By 2024, more than...