Method, device, equipment and storage medium for obtaining website address
By storing the mapping relationship between long and short URLs in the file system and using a distributed ID generation algorithm, the problems of complex deployment and poor stability of the short URL service system are solved, and efficient URL information processing and security improvement are achieved.
Patent Information
- Application Number
- CN202310207432.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-28
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2043-02-28
AI Technical Summary
The existing short URL service system relies on Redis and databases, which is complex to deploy, has poor stability, is unable to count search engine traffic, and the 301 redirect method prevents search engine crawlers from indexing short URL information.
The file system is used to store the mapping relationship between long and short URLs, and a distributed ID generation algorithm is used to generate a unique ID, avoiding dependence on databases and Redis, and URL retrieval is achieved through 302 redirection.
It reduces the difficulty of deployment, improves the system's operating efficiency and the security of URL information, is applicable to more scenarios, and can count search engine traffic.
Smart Images

Figure CN116095039B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for obtaining a website. Background Art
[0002] Short URL services, as the name suggests, convert long URLs into shorter ones. Long URLs are too lengthy and cannot be used in scenarios with character length requirements, such as text messages, Weibo, and QR code generation. Current URL shortening solutions often rely on tools like Redis and databases, making deployment cumbersome. The HTTP protocol uses two redirect types: 301 and 302. 301 is a permanent redirect, while 302 is a temporary redirect. In URL shortening services, each end address remains unchanged after generation, making the use of 301 consistent with HTTP semantics. With the 301 method, search engine crawlers like Google and Baidu directly retrieve the redirected URL and do not index the shortened URL. Consequently, traffic from search engines does not pass through the URL shortening system, making it impossible to collect user information and visit statistics.
[0003] Currently, the system needs to rely on software such as databases and Redis, which makes the entire deployment and operation process complicated and prone to problems. It is difficult to ensure the stability of the system operation, and when the short URL service traffic is relatively large, it is easy to overwhelm the system. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a URL acquisition method, apparatus, device, and storage medium that can be applied to more scenarios, reduce deployment difficulty, and improve the security of URL information and the operating efficiency of the system. The specific solution is as follows:
[0005] In a first aspect, the present application discloses a method for obtaining a website address, comprising:
[0006] Receive a URL acquisition request sent by a client, and obtain request information in the URL acquisition request;
[0007] Searching for a corresponding target file based on the request information;
[0008] If the target file is found, the target long URL information is obtained from the target file, and the long URL information and a redirect request are returned to the client, so that the target page is accessed by redirecting the long URL information.
[0009] Optionally, before receiving the URL acquisition request sent by the client, the method further includes:
[0010] Set up the seed folder and mapping folder in the target storage directory;
[0011] Generate a preset number of seed IDs using a preset seed ID generation method, create a blank file with a corresponding name based on each seed ID, and store all the blank files in the seed folder;
[0012] Determine a target blank file from all the blank files, and move the target blank file to the mapping folder;
[0013] Writing the corresponding long URL information into the target blank file to obtain a filled file;
[0014] The short URL information corresponding to the long URL information is generated based on the file name of the filled file.
[0015] Optionally, generating a preset number of seed IDs by using a preset seed ID generation method includes:
[0016] Call the distributed ID algorithm to generate the first ID in the first hexadecimal format;
[0017] Calling a base conversion algorithm to convert the first ID in the first base format into a second ID in a binary format;
[0018] Accordingly, the blank file with the corresponding name is created based on each seed ID, including:
[0019] The blank file named as the second id is created based on each second id, and after the blank file is successfully created, the corresponding second id is deleted.
[0020] Optionally, before determining the target blank file from all the blank files, the method further includes:
[0021] Determine whether the seed folder is empty;
[0022] If the seed folder is empty, re-enter the step of generating a preset number of seed IDs by a preset seed ID generation method;
[0023] Accordingly, determining the target blank file from all the blank files includes:
[0024] If the seed folder is not empty, a target blank file is determined from all the blank files.
[0025] Optionally, generating short URL information corresponding to the long URL information based on the file name of the filled file includes:
[0026] Get the preset short URL fixed information;
[0027] Determine the file name of the filled file as the short URL change information;
[0028] The fixed short URL information and the changing short URL information are concatenated to obtain the short URL information corresponding to the long URL information.
[0029] Optionally, searching for a corresponding target file based on the request information includes:
[0030] Parsing the request information to obtain the short URL change information;
[0031] Searching for the corresponding target file from the mapping folder based on the short URL change information;
[0032] If the corresponding target file is not found, a prompt page indicating that no information is found is returned.
[0033] Optionally, before receiving the URL acquisition request sent by the client and acquiring the request information in the URL acquisition request, the method further includes:
[0034] When receiving the access request sent by the client, a webpage for displaying the mapping relationship between the short URL information and the long URL information is provided to the client, so that the client generates the URL acquisition request according to the selected target short URL information.
[0035] In a second aspect, the present application discloses a device for obtaining a website address, comprising:
[0036] A request information acquisition module is used to receive a URL acquisition request sent by a client and obtain the request information in the URL acquisition request;
[0037] A file search module, configured to search for a corresponding target file based on the request information;
[0038] A long URL acquisition module is used to obtain target long URL information from the target file if the target file is found;
[0039] The redirection module is used to return the long URL information and the redirection request to the client so as to access the target page by redirecting the long URL information.
[0040] In a third aspect, the present application discloses an electronic device, comprising:
[0041] Memory, used to store computer programs;
[0042] The processor is used to execute the computer program to implement the steps of the website acquisition method disclosed above.
[0043] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the website acquisition method disclosed above is implemented.
[0044] It can be seen that the present application provides a method for obtaining a URL, including: receiving a URL obtaining request sent by a client, and obtaining the request information in the URL obtaining request; searching for a corresponding target file based on the request information; if the target file is found, obtaining the target long URL information from the target file, and returning the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information. It can be seen that the present application stores the mapping relationship between long URLs and short URLs in the target file. When the user sends a URL obtaining request, the target file is determined according to the request information in the URL obtaining request, thereby obtaining the target long URL information in the target file and returning it. It is applicable to more scenarios, reduces the deployment difficulty, and improves the security of URL information and the operating efficiency of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0046] Figure 1 A flow chart of a method for obtaining a website disclosed in this application;
[0047] Figure 2 A flowchart of a specific URL acquisition method disclosed in this application;
[0048] Figure 3 This is a schematic diagram of the short URL structure disclosed in this application;
[0049] Figure 4 A schematic diagram of the structure of the URL acquisition device provided in this application;
[0050] Figure 5 This is a structural diagram of an electronic device provided in this application. DETAILED DESCRIPTION
[0051] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0052] At present, long URL information is too lengthy and cannot be used in scenarios with word length requirements such as text messages, Weibo, and QR code generation. At the same time, current short URL service solutions usually rely on Redis, databases, etc., which are more troublesome to deploy. There are two redirection methods in the HTTP protocol, 301 and 302, of which 301 is a permanent redirection and 302 is a temporary redirection. In the short address service, for the 301 method, search engine crawlers such as Google and Baidu will directly obtain the redirected URL information when crawling data, and will not include the short URL. Therefore, the traffic coming through the search engine will not pass through the short URL system, so that these traffic information cannot be counted, and user information, access statistics and other information cannot be collected. To this end, the present application provides a URL acquisition method that uses the 302 redirection method, which can be applied to more scenarios, reduces the difficulty of deployment, and improves the security of URL information and the operating efficiency of the system.
[0053] The embodiment of the present invention discloses a method for obtaining a website address. Figure 1 As shown, the method includes:
[0054] Step S11: receiving a URL acquisition request sent by a client, and acquiring request information in the URL acquisition request.
[0055] In this embodiment, a URL acquisition request sent by a client is received, and the request information in the URL acquisition request is obtained. Specifically, the request information is parsed to obtain the short URL change information; based on the short URL change information, the corresponding target file is searched from the mapping folder; if the corresponding target file is not found, a prompt page indicating that no information is found is returned. It should be noted that before receiving the URL acquisition request sent by the client, when receiving the access request sent by the client, a web page for displaying the mapping relationship between the short URL information and the long URL information is provided to the client, so that the client can generate the URL acquisition request based on the selected target short URL information.
[0056] It can be understood that the Short URL service is a formal conversion of longer URLs into shorter ones. With the help of short URLs, lengthy URLs can be converted into short URLs, making it easier for users to use them in scenarios with character length requirements, such as SMS, Weibo, and QR code generation. Furthermore, various reporting functions such as statistics can be provided based on the monitoring of short URLs. Current short URL service solutions usually rely on Redis, databases, etc., which are more cumbersome to deploy. This solution will be based on the functions of the file system to implement a short URL system that does not rely on other systems.
[0057] Step S12: searching for a corresponding target file based on the request information.
[0058] In this embodiment, after receiving a URL acquisition request from a client and obtaining the request information in the URL acquisition request, the corresponding target file is searched based on the request information. Specifically, the request information is parsed to obtain the short URL change information; based on the short URL change information, the corresponding target file is searched in the mapping folder; if the corresponding target file is not found, a page indicating that no information was found is returned.
[0059] Step S13: If the target file is found, the target long URL information is obtained from the target file, and the long URL information and the redirection request are returned to the client, so that the target page is accessed by redirecting the long URL information.
[0060] In this embodiment, after searching for the corresponding target file based on the request information, if the target file is found, the target long URL information is obtained from the target file, and the long URL information and a redirect request are returned to the client so that the target page can be accessed by redirecting the long URL information. It is understood that if the target file is found, the content of the target file is read, that is, the original long URL is obtained, and then a 302 redirect request is sent to the client, where the redirected address is the obtained original long URL (i.e., the long URL information), so that after receiving the redirect request, the user can access the corresponding target page according to the long URL information.
[0061] For example, when a request for a short URL arrives, the request URL is obtained and the changing part, such as "Asef33", is parsed; based on the string of this changing part, the corresponding file is searched in the mapping folder; if not found, a prompt page indicating that the file was not found is returned; if found, the content of this file is read to obtain the original long URL; a 302 redirect request is sent to the client, where the redirected address is the long URL obtained in the previous step.
[0062] This application saves the mapping between long and short URLs in a file, thus avoiding reliance on a database; generates a self-incrementing unique ID (i.e., a seed ID) through a distributed ID generation algorithm, removing reliance on databases, Redis, etc.; pre-generates seed IDs through scheduled tasks to improve system efficiency; and randomly obtains seed IDs, which can avoid generating continuous values and improve security. Therefore, the solution provided by this application does not need to rely on third-party systems such as databases and Redis, making it easy to deploy; the original long URL can be quickly located through the file, with high system operating efficiency; and the seed ID file is randomly obtained each time to prevent hacker attacks due to continuous IDs.
[0063] It can be seen that the present application provides a method for obtaining a URL, including: receiving a URL obtaining request sent by a client, and obtaining the request information in the URL obtaining request; searching for a corresponding target file based on the request information; if the target file is found, obtaining the target long URL information from the target file, and returning the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information. It can be seen that the present application stores the mapping relationship between long URLs and short URLs in the target file. When the user sends a URL obtaining request, the target file is determined according to the request information in the URL obtaining request, thereby obtaining the target long URL information in the target file and returning it. It is applicable to more scenarios, reduces the deployment difficulty, and improves the security of URL information and the operating efficiency of the system.
[0064] See also Figure 2 As shown, the embodiment of the present invention discloses a method for obtaining a website address. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution.
[0065] Step S21: Set a seed folder and a mapping folder in the target storage directory.
[0066] In this embodiment, a seed folder and a mapping folder are set up in the target storage directory. It can be understood that a directory for storing short URL related files is set up, and within this directory, two subdirectories are created by the program: a seed directory and a mapping directory; the seed directory is used to store unused seed IDs, and the mapping directory is used to store the mapping relationship between long and short URLs that have been used.
[0067] Step S22: Generate a preset number of seed IDs using a preset seed ID generation method, create a blank file with a corresponding name based on each seed ID, and store all the blank files in the seed folder.
[0068] In this embodiment, after setting up a seed folder and a mapping folder in the target storage directory, a preset number of seed IDs are generated using a preset seed ID generation method, and a blank file with a corresponding name is created based on each seed ID, and all the blank files are stored in the seed folder. Specifically, a distributed ID algorithm is called to generate a first ID in a first base format; a base conversion algorithm is called to convert the first ID in the first base format into a second ID in a binary format; a blank file named the second ID is created based on each second ID, and after the blank file is successfully created, the corresponding second ID is deleted. It is understandable that a threshold for the number of seed IDs is set, such as 5000, which means that 5000 seed IDs are generated each time. Among them, the first base format is decimal and the second binary format is 62-base; 62-base refers to a method of encoding using 62 characters such as 0~9A~Za~z. After the 62-base conversion, the result will only contain numbers + lowercase letters + uppercase letters, which are characters that meet the requirements of a normal URL. Converting decimal to base 62 can effectively shorten the number of characters. In base 62, if there are 6-bit characters, there are already 56 billion combinations, which meets general needs.
[0069] The auto-increment ID generation function periodically scans the number of files in the seed directory. If the number of files is less than the seed ID threshold, the seed ID generation process is invoked to generate a new seed ID. The seed ID generation process consists of the following steps: calling the distributed ID algorithm to generate a decimal ID each time; calling the decimal-to-sixty-two algorithm to convert the decimal data to sixty-two; and creating a blank file in the seed directory named with the sixty-two numeric value.
[0070] Step S23: determining a target blank file from all the blank files, and moving the target blank file to the mapping folder.
[0071] In this embodiment, a blank file with a corresponding name is created based on each seed ID. After all the blank files are stored in the seed folder, a target blank file is determined from all the blank files and the target blank file is moved to the mapping folder. It should be noted that before determining the target blank file from all the blank files, a determination is made as to whether the seed folder is empty. If the seed folder is empty, the step of generating a preset number of seed IDs using a preset seed ID generation method is re-entered. If the seed folder is not empty, a target blank file is determined from all the blank files and the target blank file is moved to the mapping folder.
[0072] Step S24: writing the corresponding long URL information into the target blank file to obtain a filled file.
[0073] In this embodiment, a target blank file is determined from all the blank files, the target blank file is moved to the mapping folder, and then the corresponding long URL information is written into the target blank file to obtain a populated file. It can be understood that the corresponding long URL information is written into the target blank file to establish a mapping relationship between the short URL and the long URL. The file name of the resulting populated file is the short URL information, and the populated file contains the corresponding long URL information.
[0074] Step S25: generating short URL information corresponding to the long URL information based on the file name of the filled file.
[0075] In this embodiment, after the corresponding long URL information is written into the target blank file to obtain the filled file, the short URL information corresponding to the long URL information is generated based on the file name of the filled file. A generated short URL will contain two parts: a fixed part and a variable part. The variable part is the value converted from base 62 based on the self-incrementing id, and each different URL corresponds to a different variable part. Specifically, the preset short URL fixed information is obtained; the file name of the filled file is determined as the short URL variable information; the short URL fixed information and the short URL variable information are spliced to obtain the short URL information corresponding to the long URL information. For example, Figure 3 As shown, the fixed portion of the short URL is set to "http: / / example.com / " and the variable portion is set to "xA233ff." Currently, conventional designs store the relationship between short and long URLs in a database. To reduce database pressure, data caching is performed using Redis. This is typically accomplished through the database or Redis's auto-increment ID generation process.
[0076] It's understood that the short URL generation process is triggered when a short URL generation request is received, where the request parameters contain the original URL to be processed, i.e., the long URL. This process primarily involves the following steps: checking the file in the seed directory; if it's empty, re-invoking the seed ID generation process; randomly selecting a file and moving it to the mapping folder; writing the long URL to this file; returning the file's filename as the variable portion of the short URL; and concatenating the fixed and variable portions to return the final short URL.
[0077] Step S26: receiving the URL acquisition request sent by the client, and acquiring the request information in the URL acquisition request.
[0078] Step S27: searching for a corresponding target file based on the request information.
[0079] Step S28: If the target file is found, the target long URL information is obtained from the target file, and the long URL information and the redirection request are returned to the client, so that the target page is accessed by redirecting the long URL information.
[0080] For the specific contents of the above steps S26 to S28, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0081] It can be seen that the embodiment of the present application sets a seed folder and a mapping folder under the target storage directory; generates a preset number of seed IDs through a preset seed ID generation method, and creates a blank file with a corresponding name based on each seed ID, and stores all the blank files in the seed folder; determines the target blank file from all the blank files, and moves the target blank file to the mapping folder; writes the corresponding long URL information in the target blank file to obtain a filled file; generates short URL information corresponding to the long URL information based on the file name of the filled file; receives a URL acquisition request sent by the client, and obtains the request information in the URL acquisition request; searches for the corresponding target file based on the request information; if the target file is found, obtains the target long URL information from the target file, and returns the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information. It is applicable to more scenarios, reduces deployment difficulty, and improves the security of URL information and the operation efficiency of the system.
[0082] See also Figure 4 As shown, the embodiment of the present application also discloses a device for obtaining a website address, including:
[0083] The request information acquisition module 11 is used to receive a URL acquisition request sent by a client and obtain the request information in the URL acquisition request;
[0084] A file search module 12, configured to search for a corresponding target file based on the request information;
[0085] The long URL acquisition module 13 is configured to acquire target long URL information from the target file if the target file is found;
[0086] The redirection module 14 is configured to return the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information.
[0087] It can be seen that the present application includes: receiving a URL acquisition request sent by a client, and obtaining the request information in the URL acquisition request; searching for the corresponding target file based on the request information; if the target file is found, obtaining the target long URL information from the target file, and returning the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information. It can be seen that the present application stores the mapping relationship between long URLs and short URLs in the target file. When the user sends a URL acquisition request, the target file is determined according to the request information in the URL acquisition request, thereby obtaining the target long URL information in the target file and returning it. It is applicable to more scenarios, reduces the deployment difficulty, and improves the security of URL information and the operating efficiency of the system.
[0088] In some specific embodiments, the request information acquisition module 11 specifically includes:
[0089] Folder setting unit, used to set the seed folder and mapping folder under the target storage directory;
[0090] A first ID generating unit, configured to call a distributed ID algorithm to generate a first ID in a first hexadecimal format;
[0091] A second ID acquisition unit is configured to call a base conversion algorithm to convert the first ID in the first base format into a second ID in a binary format;
[0092] a blank file creating unit, configured to create the blank file named as the second ID based on each second ID, and delete the corresponding second ID after the blank file is successfully created;
[0093] A seed folder determination unit, configured to determine whether the seed folder is empty;
[0094] a seed ID generating unit, configured to re-enter the step of generating a preset number of seed IDs by a preset seed ID generating method if the seed folder is empty;
[0095] a target blank file moving unit, configured to determine a target blank file from all the blank files if the seed folder is empty, and move the target blank file to the mapping folder;
[0096] A filled file obtaining unit, configured to write corresponding long URL information into the target blank file to obtain a filled file;
[0097] A short URL fixed information acquisition unit, used to acquire preset short URL fixed information;
[0098] a short URL change information determining unit, configured to determine the file name of the filled file as the short URL change information;
[0099] A short URL information acquisition unit, configured to combine the fixed short URL information and the variable short URL information to obtain the short URL information corresponding to the long URL information;
[0100] a webpage providing unit, configured to, upon receiving an access request sent by the client, provide the client with a webpage for displaying a mapping relationship between the short URL information and the long URL information, so that the client can generate the URL acquisition request according to the selected target short URL information;
[0101] The request information obtaining unit is configured to receive a URL obtaining request sent by a client and obtain request information in the URL obtaining request.
[0102] In some specific embodiments, the file search module 12 specifically includes:
[0103] A request information parsing unit, configured to parse the request information to obtain the short URL change information;
[0104] A target file acquiring unit, configured to search the corresponding target file from the mapping folder based on the short URL change information;
[0105] The prompt page returning unit is used to return a prompt page indicating that no information is found if the corresponding target file is not found.
[0106] In some specific embodiments, the long URL acquisition module 13 specifically includes:
[0107] The long URL obtaining unit is used to obtain target long URL information from the target file if the target file is found.
[0108] In some specific embodiments, the redirection module 14 specifically includes:
[0109] The redirection unit is used to return the long URL information and the redirection request to the client, so as to access the target page by redirecting the long URL information.
[0110] Furthermore, an embodiment of the present application also provides an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram should not be considered as any limitation to the scope of application of the present application.
[0111] Figure 5This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the URL acquisition method disclosed in any of the aforementioned embodiments. Furthermore, the electronic device 20 in this embodiment may be a computer.
[0112] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0113] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0114] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, and can be Windows Server, NetWare, Unix, Linux, etc. In addition to including a computer program capable of performing the website address acquisition method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program capable of performing other specific tasks.
[0115] Furthermore, an embodiment of the present application also discloses a storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the steps of the website acquisition method disclosed in any of the aforementioned embodiments are implemented.
[0116] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0117] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0118] The above describes in detail a URL acquisition method, apparatus, device, and storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only intended to help understand the method and core concept of the present invention. At the same time, for those skilled in the art, according to the concept of the present invention, there may be changes in the specific implementation methods and application scope. In summary, the contents of this specification should not be understood as limiting the present invention.
Claims
1. A method for obtaining a website, characterized in that: include: Set up the seed folder and mapping folder in the target storage directory; The target storage directory includes a seed directory and a mapping directory. The seed directory is used to store unused seed IDs, and the mapping directory is used to store the mapping relationship between long and short URLs that have been used. Generate a preset number of seed IDs using a preset seed ID generation method, create a blank file with a corresponding name based on each seed ID, and store all the blank files in the seed folder; Determine a target blank file from all the blank files, and move the target blank file to the mapping folder; Writing the corresponding long URL information into the target blank file to obtain a filled file; Generating short URL information corresponding to the long URL information based on the file name of the filled file; wherein, generating the short URL information corresponding to the long URL information based on the file name of the filled file includes: obtaining preset fixed short URL information; determining the file name of the filled file as the short URL variation information; splicing the fixed short URL information and the short URL variation information to obtain the short URL information corresponding to the long URL information; Receive a URL acquisition request sent by a client, and obtain request information in the URL acquisition request; Searching for a corresponding target file based on the request information; wherein searching for a corresponding target file based on the request information comprises: parsing the request information to obtain the short URL change information; searching for a corresponding target file in the mapping folder based on the short URL change information; and returning a prompt page indicating that no information was found if the corresponding target file is not found; If the target file is found, the target long URL information is obtained from the target file, and the long URL information and a redirect request are returned to the client, so that the target page is accessed by redirecting the long URL information.
2. The method for obtaining a website address according to claim 1, wherein: The method of generating a preset number of seed IDs by using a preset seed ID generation method includes: Call the distributed ID algorithm to generate the first ID in the first hexadecimal format; Calling a base conversion algorithm to convert the first ID in the first base format into a second ID in a binary format; Accordingly, the blank file with the corresponding name is created based on each seed ID, including: The blank file named as the second id is created based on each second id, and after the blank file is successfully created, the corresponding second id is deleted.
3. The method for obtaining a website address according to claim 1, wherein: Before determining the target blank file from all the blank files, the method further includes: Determine whether the seed folder is empty; If the seed folder is empty, re-enter the step of generating a preset number of seed IDs by a preset seed ID generation method; Accordingly, determining the target blank file from all the blank files includes: If the seed folder is not empty, a target blank file is determined from all the blank files.
4. The method for obtaining a website address according to any one of claims 1 to 3, wherein: Before receiving the URL acquisition request sent by the client and obtaining the request information in the URL acquisition request, the method further includes: When receiving the access request sent by the client, a webpage for displaying the mapping relationship between the short URL information and the long URL information is provided to the client, so that the client generates the URL acquisition request according to the selected target short URL information.
5. A device for obtaining a website address, characterized in that: include: Folder setting unit, used to set the seed folder and mapping folder under the target storage directory; The target storage directory includes a seed directory and a mapping directory. The seed directory is used to store unused seed IDs, and the mapping directory is used to store the mapping relationship between long and short URLs that have been used. Generate a preset number of seed IDs using a preset seed ID generation method, create a blank file with a corresponding name based on each seed ID, and store all the blank files in the seed folder; a target blank file moving unit, configured to determine a target blank file from all the blank files, and move the target blank file to the mapping folder; A folder setting unit, configured to write corresponding long URL information into the target blank file to obtain a filled file; A short URL fixed information acquisition unit, used to acquire preset short URL fixed information; a short URL change information determining unit, configured to determine the file name of the filled file as the short URL change information; A short URL information acquisition unit, configured to combine the fixed short URL information and the variable short URL information to obtain the short URL information corresponding to the long URL information; A request information acquisition module is used to receive a URL acquisition request sent by a client and obtain the request information in the URL acquisition request; The file search module is configured to search for a corresponding target file based on the request information; wherein the file search module includes: a request information parsing unit configured to parse the request information to obtain the short URL change information; a target file acquisition unit configured to search for the corresponding target file from the mapping folder based on the short URL change information; and a prompt page return unit configured to return a prompt page indicating that no information was found if the corresponding target file is not found. A long URL acquisition module is used to obtain target long URL information from the target file if the target file is found; The redirection module is used to return the long URL information and the redirection request to the client so as to access the target page by redirecting the long URL information.
6. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the method for obtaining a website address as claimed in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that Used to store a computer program; wherein, when the computer program is executed by a processor, the website acquisition method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Website access method and device, electronic equipment and storage medium
CN111797334A