URL Shortening Site(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缩短站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:URL缩短站点


- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01