网址缩短网站 [英] URL Shortening Site
问题描述
我工作的一个网址缩短网站,使用PHP,MySQL和Apache的。网址缩短的总体思路,我看开源项目:用户给出了一个URL链接,系统获取ID为从数据库链接。然后转换量ID X基本系统(我使用的基地36)。然后使用Apache的mod_rewrite和创建缩短的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?
推荐答案
我觉得你说的很正确的方式。
I think you are quite on the right way.
有一件事情像你说我不会做,虽然是这部分:
One thing I would not do like you said, though, is about this part :
然后使用URL重写,并创建 缩短的URL,然后重定向。
then use apache mod_rewrite and create shorten url and then redirect.
我不认为我会创建一个Apache重写规则,也不能使用的mod_rewrite
。
I don't think I'd create an Apache RewriteRule, nor use mod_rewrite
.
当接收到一个短网址,如 short.com/MYID
,标识将:
When receiving an short url, like short.com/MYID
, Id would :
- 在MYID部分解密的ID号DB
- 从数据库中读取URL
- 只是重定向到一些服务器code,它的URL(如PHP,使用的
头
功能)
像这样的一点我想:
// fetch $urlFull from DB (corresponding to the MYID received in GET)
header('HTTP/1.x 301 Moved Permanently');
header('Location: ' . $urlFull);
die;
(编辑)如果的mod_rewrite
你的意思是变换short.com/MYID到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 :-)
这篇关于网址缩短网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!