百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

php-url-shortener

> 编程语言
开源

简单的 PHP URL 缩短器,如 mths.be 所使用

334 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

简单的 PHP URL 缩短器,如 mths.be 所使用

Simple PHP URL shortener

Requires PHP ≥ 5.4.0 or higher.

Installation

  1. Download the source code as located within this repository, and upload it to your web server.
  2. Use database.sql to create the redirect table in a database of choice. (Do not delete the INSERT statement on line 10 as it is needed to initialize the database.)
  3. Edit config.php and enter your database credentials.
  4. For additional security through obscurity™, consider renaming shorten.php to a secret file name of your choosing and tweaking the .htaccess file (line 3) accordingly.

Features

  • Redirect to Twitter when given a numerical slug, e.g. http://mths.be/8065633451249664 → http://twitter.com/mathias/status/8065633451249664.
  • Redirect to your Twitter account when @ is used as a slug, e.g. http://mths.be/@ → http://twitter.com/mathias.
  • Redirect to your Google Plus account when + is used as a slug, e.g. http://mths.be/+ → https://plus.google.com/u/0/116553353277057965424/posts.
  • Redirect to your main website when no slug is entered, e.g. http://mths.be/ → http://mathiasbynens.be/.
  • Redirect to a specific page on your main website when an unknown slug (not in the database) is used, e.g. http://mths.be/demo/jquery-size → http://mathiasbynens.be/demo/jquery-size.
  • Ignores weird trailing characters (!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, @, :, ;, ``, [, \, ], ^, _, {, |, }, ~) in slugs — useful when your short URL is run through a crappy link parser, e.g. http://mths.be/aaa) → same effect as visiting http://mths.be/aaa.
  • Generates short, easy-to-type URLs using only [a-z] characters.
  • Doesn’t create multiple short URLs when you try to shorten the same URL. In this case, the script will simply return the existing short URL for that long URL.
  • DRY, minimal code.
  • Correct, semantic use of the available HTTP status codes.
  • Can be used with Twitter for iPhone. Just go to Settings › Services › URL Shortening › Custom… and enter http://yourshortener.ext/shorten?url=%@.

Favelets / Bookmarklets

Prompt

javascript
javascript:(function(){const%20q=prompt('URL:');if(q){location='https://yourshortener.ext/shorten?url='+encodeURIComponent(q)}}());

Shorten this URL

javascript
javascript:(function(){location='https://yourshortener.ext/shorten?url='+encodeURIComponent(location.href)}());

License

This script is available under the MIT license.

Author

  • Mathias Bynens

Contributors

  • Peter Beverloo
  • Tomislav Biscan

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言