当前位置: 首页 > 互联网 > 正文

使用 Yourls 强化你的短网址系统

在《打造 WordPress 的简易短网址 》一文中,介绍了利用 WordPress 永久链接 打造简易山寨的短网址系统,但是这种方法有种缺憾,比如网站要搬家了,.htaccess文件被修改了,或者自己要查看短网址被访问的次数,这时候都是一件很麻烦的事情,所以,这里我推荐使用由国外著名 WordPress 插件大师级人物 Ozh RichardLester Chan 一起写的 Yourls

 

一、介绍作者

使用 WordPress 有点年份的老鸟一定对 Ozh (法国淫) 和 Lester Chan (新加坡淫) 两位大师级插件作者不会陌生,Ozh’s 插件系列,以及 Lester Chan 的 WP- 系列插件,或许你不知道他们的名字,但是 Ozh’s Better Feed WP-PostviewsWP-Postnavi 等等大名鼎鼎的插件你一定不会陌生,没错,都是这两位作者的杰作。

Ozh Lester Chan 的插件流行度都很大,这次两人联手制作的 Yourls ,引起无数粉丝狂欢,因为这款 php程序 本来是 Ozh 御用的,后来在广大爱好者的要求下,和 Lester Chan 一起重写,然后发布,嘎嘎。

八卦一下:Ozh 的御用私人短网址地址是 ozh.inLester Chan 的是 lc.sg

二、Yourls 下载安装使用介绍

下载:

Yourls 的最新版本是 1.1 ,可以前往 http://code.google.com/p/yourls/downloads/list 进行下载,但是 1.1 有个致命的bug,不知道是 Ozh 浪漫过头了,还是 Lester Chan 也没看到,用非记事本打开 yourls-go.php,找到第23行,然后,

原句是:var_dump($url); die(); 直接注释修改修给为 //var_dump($url); die();

不修改的话生成短网址的时候会出错,感谢 Lorz 发现

安装:

Yourls 的安装方法也比较简单,首先打开 includes\config-sample.php

找到

/** MySQL database username */
define(‘YOURLS_DB_USER’, ‘dbuser’); // MySQL 数据库用户名

/** MySQL database password */
define(‘YOURLS_DB_PASS’, ‘dbpassword’); // MySQL 数据库密码

/** The name of the database for YOURLS */
define(‘YOURLS_DB_NAME’, ‘shorturl’); // MySQL 数据库名称

/** MySQL hostname */
define(‘YOURLS_DB_HOST’, ‘localhost’); // MySQL 数据库所在主机,99%情况不用修改,Godaddy的空间需要修改

/** MySQL URL table name. Don’t change this if in doubt. */
define(‘YOURLS_DB_TABLE_URL’, ‘url’); // 创建的 Yourls 的表的名字,同一个数据库放多个 Yourls 程序时需要修改

/** MySQL Next ID table name. Don’t change this if in doubt. */
define(‘YOURLS_DB_TABLE_NEXTDEC’, ‘next_id’); // 同上

修改成相应的数据库信息

找到

/*
** Site options
*/

/** Short domain URL, no trailing slash */
define(‘YOURLS_SITE’, ‘http://site.com’); //站点域名

/** Timezone GMT offset */
define(‘YOURLS_HOURS_OFFSET’, 0); //时区修改,基本没必要

/** Private means protected with login/pass as defined below. Set to false for public usage. */
define(‘YOURLS_PRIVATE’, true); //私人用还是公开用,公开的话写false,一般都私人用

/** A random secret hash used to encrypt cookies. You don’t have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookiekey.php **/
define(‘YOURLS_COOKIEKEY’, ‘qQ4KhL_pu|s@Zm7n#%:b^{A[vhm’); //访问 http://yourls.org/cookiekey.php 取得一个唯一的 Key 并且修改填入

/** Username(s) and password(s) allowed to access the site */
$yourls_user_passwords = array(
‘username’ => ‘password’,
‘username2’ => ‘password2’ // You can have one or more ‘login’=>’password’ lines
); //这里是管理员的用户名和密码,默认有两组,可以删除一组或者增加N多组

根据自己的需要进行修改

然后把 config-sample.php 重命名为 config.php ,确保你的空间支持 PHP + MySQL 以及基本的几个组件(Mod-Rewrite功能,Curl 等,一般的空间都支持)

最后执行 http://你的地址/admin/install.php 进行安装即可

使用 Apache 主机的朋友,请确定你的空间支持 Mod-Rewrite ,就是可以用 .htaccess 文件进行伪静态,程序根目录已经给你写好 .htaccess 所以不用自己再写;使用 Nginx 的童鞋,伪静态的规则是:

location /
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = “21”){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
}
rewrite ^/([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 last;
}

已经测试无误,因为本人的 Yourls 就是放在 Nginx 主机上的。

使用:

Yourls 提供两种 URL 编码形式,一种是只有小写的 Base 36 encoding 0123456789abcdefghijklmnopqrstuvwxyz,还有一种是有大小写的 Base 62 encoding 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,一般来说,使用默认的 Base 36 即可,因为要使用 Base 62 需要空间支持 phpBCMath 扩展,而且没什么必要,个人用 Base 32 足矣,官方宣称可以创建 4,738,381,338,321,617,846 个短网址,天哪,这得用到猴年马月,所以没什么特殊情况就不用修改 config.php ,用默认的编码即可。

后台地址是 http://你的地址/admin/ 当然可以修改 admin 文件夹的名字以防万一,管理员的用户名和密码都在 includes\config.php 里自己设置,不推荐使用常用的密码,毕竟是明文形式储存,所以想一个复杂点的没用过的密码最好不过。

登陆后台,就可以看到清爽的后台界面,在后台增加短网址之类的就不用我说了,UI 界面非常友好,如图:

Yourls

为自己的博客文章或页面生成短网址有两种方式,一种就是截图所示的后台自己生成,一种是通过 API 或 WordPress 插件。

默认的 API 地址就是 http://你的地址/yourls-api.php 官方的 API 文档在这里:http://yourls.org/#API 虽然不够详细,但是也够用了。要是觉得一头雾水的话,Lorz 童鞋为我们做好了 JavaScript 脚本:

http://lorz.me/short-url-yourls/

怎么样,还是很拉风的吧。

在阅读器中无效的,请移步到这里:http://zou.lu/yourls/
更加方便的一种方法是使用 Ozh 写的 WordPress 插件YOURLS: WordPress to Twitter
下载,上传,后台激活,然后按照我这样的设置即可(国外空间的童鞋还可以选择发送到 Twitter ,国内空间的童鞋就没福气了,原因不详,我文盲,不知道为啥 Twitter 不能直接上,连 API 都封。)
Yourls

Ozh 提供了两个 Template Tags

<?php if (function_exists(‘wp_ozh_yourls_url’)) wp_ozh_yourls_url(); ?> 用来直接输出生成的短网址地址,可以用在主题文件的 single.php 、 page.php 等,这个函数输出的内容如下:

<a href=”http://gxf.in/1” rel="nofollow alternate shorter" title="short URL">http://gxf.in/1</a>

<?php if (function_exists(‘wp_ozh_yourls_head_linkrel’)) wp_ozh_yourls_head_linkrel(); ?> 是一个放在头部的东东,对 Google 等搜索引擎肯定有好处,对百度这种那就算了。这个函数输出的内容如下:

<link rel="alternate short shorter shorturl" href=”http://gxf.in/1” />

帅吧,还犹豫什么,拿起你手中的短域名开始你的短网址之旅吧,Showfom 小帅锅已经把文章页面里的短网址全部替换成自己架设的 Yourls ,而且域名就是模仿 Ozh 的,注册了个酷酷的 gxf.in (拼音缩写),私人短网址的时代到来了!

三、个人意见

个人觉得Yourls最那啥的一点就是,默认是按照顺序来排列短网址,而不是通常的随机字母数字结合,希望作者能在下一个版本改进。

PS: Yourls 已经改进很多,比如在短网址最后加 + 符号即可查看统计次数,前台也有简单的模板样式,详见: http://gxf.in/
来自:http://zou.lu/yourls/

本文固定链接: http://web.wqz.me/106.html | 网络手抄本

该日志由 网络手抄本 于2014年06月13日发表在 互联网 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 使用 Yourls 强化你的短网址系统 | 网络手抄本
关键字: ,

使用 Yourls 强化你的短网址系统:目前有15 条留言

  1. 15楼
    Rosa Keller:

    Thank you a lot for sharing this with all people you actually realize what you’re talking approximately! Bookmarked. Kindly also consult with my site =). We could have a link trade arrangement among us

    2020-11-13 下午12:49 [回复]
  2. I know this website presents quality depending articles or reviews and other material, is there any other web page which presents these kinds of stuff in quality?

    2020-11-20 上午1:51 [回复]
  3. 13楼
    Michale Macy:

    An outstanding share! I have just forwarded this onto a friend who was doing a little research on this. And he in fact bought me dinner because I stumbled upon it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanks for spending time to discuss this topic here on your internet site.

    2020-12-29 下午4:36 [回复]
  4. 12楼
    Rene Goheen:

    Remarkable! Its in fact awesome post, I have got much clear idea about from this post.

    2020-12-31 上午1:50 [回复]
  5. 11楼
    Carmela Sapp:

    For newest news you have to go to see web and on internet I found this website as a finest web page for most recent updates.

    2020-12-31 上午4:49 [回复]
  6. Excellent pieces. Keep posting such kind of information on your page. Im really impressed by your site.
    Hi there, You’ve performed a great job. I will definitely digg it and individually suggest to my friends. I’m confident they will be benefited from this site.

    2020-12-31 上午5:23 [回复]
  7. Excellent post. I used to be checking constantly this weblog and I’m impressed! Very useful info particularly the remaining phase 🙂 I deal with such info much. I was looking for this certain information for a very lengthy time. Thanks and best of luck.

    2020-12-31 上午5:44 [回复]
  8. I am not certain where you are getting your info, however good topic. I must spend a while studying much more or working out more. Thanks for wonderful info I was in search of this info for my mission.

    2020-12-31 上午7:26 [回复]
  9. http://108.179.216.114/
    I used to be recommended this blog by my cousin. I am no longer certain whether this publish is written by means of him as nobody else recognise such distinctive about my trouble. You are amazing! Thanks!

    2021-01-02 上午2:53 [回复]
  10. I’m impressed, I have to admit. Rarely do I encounter a blog that’s both educative and engaging, and without a doubt, you’ve hit the nail on the head. The problem is an issue that not enough people are speaking intelligently about. I am very happy I stumbled across this in my search for something concerning this.

    2021-01-02 上午11:23 [回复]
  11. Greetings! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My web site looks weird when browsing from my iphone4. I’m trying to find a theme or plugin that might be able to resolve this issue. If you have any suggestions, please share. With thanks!

    2021-01-05 上午5:44 [回复]
  12. Hi, I’m a permanent vape and CBD reviewer at https://vapetelligent.com. I’m looking for vape as well as CBD reviewers to review eliquid from Bodyrock, Freeman Vape Juice as well as Vop Sauce as well as CBD PODS from Balanced2Day! If anybody at wqz.me is interested, please get in touch! Thanks

    2021-01-05 下午9:20 [回复]
  13. 地板
    Katlyn Casper:

    When we were born we knew what are the nine qualities of unconditional love were. Masaru Emoto and the predating work of Marcel Vogel, Norman Mikesell, and lots of other Water researchers. This is the area of the neurological system that is certainly to blame for the flight or fight response.

    2021-01-10 下午4:00 [回复]
  14. It’s also a good idea to search for online reviews and testimonials off their previous clients. My personal choice has to be static location about the beach and then this motor home to be able to allow travel throughout Europe and maybe an extra property share within the States all-around take advantage of the playgrounds of Disney in Florida. People residing in Auckland charges you up to $300 per night to remain in their holiday home.

    2021-01-21 上午2:34 [回复]
  15. Webinar services can utilize their webinar software to help you out in making a group of informative webinars that will need website visitors to sign up to view. Webinar within this present time is one with the best online conferencing solutions. Since we’re in such close proximity I’d like to sit back for approximately 15-20 minutes with does tomorrow sound.

    2021-01-21 下午6:13 [回复]

发表评论

快捷键:Ctrl+Enter