URL缩短站点 [英] URL Shortening Site

查看:36
本文介绍了URL缩短站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 PHP、MySQL 和 Apache 的 URL 缩短站点.当我查看开源项目时,URL 缩短的总体思路:用户提供一个 URL 链接,系统从数据库中获取该链接的 ID.然后转换 ID X 基本系统(我使用的是 base 36).然后使用 Apache mod_rewrite 并创建缩短的 URL,然后重定向.是否所有的 URL 缩短站点都像这样工作,或者是否有一些使用除此之外的不同算法?有什么想法可以与其他 URL 缩短系统不同吗?

I am working on a URL shortening site which uses PHP, MySQL and Apache. General idea of URL shortening as I look at open source projects: user gives a URL link and the system gets ID for that link from database. Then convert the ID X base system (I am using base 36). Then use Apache mod_rewrite and create shortened URL and then redirect. Do all of the URL shortening sites work like that or do some use a different algorithm other than this? And any idea for making a difference from other URL shortening systems?

推荐答案

我认为你说的很对.

不过,我不会像你说的那样做的一件事是关于这部分:

One thing I would not do like you said, though, is about this part :

然后使用 apache mod_rewrite 并创建缩短网址,然后重定向.

then use apache mod_rewrite and create shorten url and then redirect.

我认为我不会创建 Apache RewriteRule,也不会使用 mod_rewrite.

I don't think I'd create an Apache RewriteRule, nor use mod_rewrite.


当收到一个短网址时,比如 short.com/MYID,Id 会:

  • 将MYID"部分解密为DB中的id号
  • 从数据库中获取 URL
  • 只需从某些服务器代码(如 PHP,使用 header 函数)

我猜有点像这样:

// fetch $urlFull from DB (corresponding to the MYID received in GET)
header('HTTP/1.x 301 Moved Permanently');
header('Location: ' . $urlFull);
die;


(编辑)如果 mod_rewrite 你的意思是transform short.com/MYID to short.com/id=MYID",哦,是的,在这种情况下,当然!


(edit) If by mod_rewrite you meant "transform short.com/MYID to short.com/id=MYID", oh, yes, in this case, of course !

顺便说一句,我在我的一个网站上使用了这样的东西:

I'm using something like this on one of my sites, btw :

RewriteEngine on
RewriteCond %{REQUEST_URI}  !^/index.php
RewriteRule ^(.*)$ /index.php?hash=$1   [L]


希望这会有所帮助:-)


Hope this helps :-)

这篇关于URL缩短站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆