处理(创建/提供)自定义短网址时我应该采取什么方法?

发布于 2024-11-09 01:09:38 字数 362 浏览 4 评论 0原文

需要建议!这是我对网址缩短的了解: 通常新记录 id 是从数据库中获取并转换为某种东西,比如说基数 36...

我的情况: 我需要在 URL 缩短和自动生成的 url 中具有附加功能,我还需要能够处理自定义 url。

示例:用户输入:http://google.com 并希望拥有短网址“domain/my-google”。

问题: 乍一看一切都很好,但我担心扩展,因为 url 将存储 90 天,而且数据库记录是否会增长!我可能会遇到一些性能问题!

所以问题是:在处理(创建/提供)自定义短网址时我应该采取什么方法?

need an advice! here is a what I know about url shortening:
usually new records id is taken from Database and converted to something, let's say base 36...

My situation:
I need to have a additional feature in URL shortening along with auto generated url I also need to be able process custom url.

Example: user enters : http://google.com and wants to have short url "domain/my-google".

Problem:
things are fine at the first sight, but I am worried about scaling, as urls will be stored for 90 days and if database records will grow! I might face some performance issues!

So the question: What approach should I take while processing (creating/ serving) custom short urls?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-11-16 01:09:38

这对你来说是一系列的并发症。只需一点 htaccess 编码和几行 PHP 代码,就可以编写一个非常小的脚本来解析 URL 并从中获取片段,这是很容易的部分。至于短网址 ID,那就是另一堆蠕虫了。如果你严格基于 INT 并使用数字作为你的概念,例如使用 ID 的自动递增列作为 URL 的短部分,那么事情很容易,事情将永远是唯一的,并且不用担心破坏 ID 的位置可以出现双打和三打。

这是我用过多次的
.htaccess php 如何使用 wordpress slugs对我来说总是很有效。处理其余部分,尽管我将留给您所需的构造和逻辑,但要记住您将在最终运行中查询数据库,因此请确保您的查询得到清理,因为作为 ID 的 URL 的尾随位是基于的用户输入。

This is a series of complications for you. With a little htaccess coding and a couple lines of PHP litterally a very tiny script for the over all use of parsing the URL and getting the pieces from it is the easy part. As for the short url id's thats a whole nother can of worms. if you go stricly INT based and use numerics for your concept such as with an auto-incriment column for the ID's to use as the short part of the URL things are easy, things will always be unique, and no serious worries about bashing ID's where doubles and triples can come up.

here is what I have used several times over
.htaccess php how-to wordpress slugs And it always works well for me. Handling the rest of it though Ill leave to your construct and logic desired bare in mind your going to query a DB in the end run, so make sure your query gets sanitized as the trailing bit of the URL that would be the ID is based on user input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文