Suppose the following is the list of links of your video website. If others want to crawl your data, it is very easy, and you know that the database is self -increased when you look at the rules.
http://www.xxxx.com/video/1
http://www.xxxx.com/video/2
http://www.xxxx.com/video/3
Then solve this problem, we can use short addresses, do not expose real links to the outside world, and use symmetrical encryption is a good solution.
Hashids is a good choice, which provides a programming language such as JS/PHP/Java/Python. I use it here.
The following is the Java short address service built by my Blade framework.
Create Table `t_url` (` ID` int (10) not null auto_increment, `url` text not null, primary key (` ID`)) Engine = Innodb Auto_Increment = 15 default charset = UTF8;
routing
@PathPublic Class Indexroute {// salt value Private Static Final Hashids = New Hashids ("Blade-Shorturl"); Private Urlmodel Urlmodel = New Model (); @route ("/: key") Public Void Get (Request REQ, Response response) {string key = req.pathparam (": key"). Replaceall ("[^a-Za-Z0-9]", ""); long [] numbers = hashids.Decode (key); if (key); NULL == Numbers || Numbers.Length <1) {response.text ("No found"); Return;} int id = (int) numbers [0]; string result = get (id) .geturl (); if (Result == null) {response.text ("No found"); Return;} Response.redirect (result);} @route (value = "/", method = httpmethod.get) ing index () {return "Index";} @route (value = "/", Method = httpmethod.post) Public String Save (request request, response response) {string resjsp = "Index"; Str. ing longurl = request.query ("url"); If (! Isurl (longurl)) {request.attribute ("error", "invalid url"); Return resvsp;} Integer ID = this.save (longurl); if (id == 0) { UTE (UTE "ERROR", "Save failed"); Return resvp;} string hash = hashids.encode (ID); Request.attribute ("url_hash", have); System.out.println ("id =" + id + ", url_hash = " + hash); Return resvsp;} Private Integer Save (String URL) {Return urlmodel.InSERT (). URL) .ecuteandCommit (); } Private urlmodel get (int ID) {Return urlmodel .fetchbypk (ID);} Private Final String RegX = "// B (https? | ftp | File): // [-a-Za-Z0-9+@#/%? = ~ |! .]*[-S-Za-Z0-9+@#/%= ~ |] "; Private Boolean Isurl (String URL) {if (Stringkit.isnotBlank (URL)) {Pattern Pattern = Pattern. (RegEx); Matcher Matcher = Pattern.Matcher (url); if (matcher.find ()) {Return True;}} Return false;}}Implementation effect:
Code location: https://github.com/bladejava/blade- shorturl
The above is all the contents of this article. I hope it will be helpful to everyone's learning.