我正在开发一个使用 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 会:
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缩短站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!