个人生活记录
主机优惠分享与测试

YOURLS:属于自己的短网址

香港/美国/国内高速VPS

有些朋友对老赵的短网址感兴趣询问我,很早的时候,我分享过一个wordpress插件对一些较长的地址实现URL缩短,今天,我再分享一个开源PHP程序—YOURLS。

yourls

首先,我们下载YOURLS源码,目前最新版本为1.5,直接到官网下载(http://yourls.org/)。然后,配置YOURLS。

打开includes下的config-sample.php文件,将以下项目进行适当的设置:

/** MySQL database username */
define(‘YOURLS_DB_USER’, ‘dbuser’); 将dbuser替换为你的Wordpress数据库用户名

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

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

/** MySQL hostname */
define(‘YOURLS_DB_HOST’, ‘localhost’); 数据库地址

/** MySQL tables prefix */
define(‘YOURLS_DB_PREFIX’, ‘yourls_’); yourls将要生成的表的名字前缀

/** YOURLS installation URL, no trailing slash */
define(‘YOURLS_SITE’, ‘http://site.com’); // 你的短域名,也就是你要安装的目录所绑定的域名

/** Timezone GMT offset */
define(‘YOURLS_HOURS_OFFSET’, 0); 时区设置,不用改

/** Allow multiple short URLs for a same long URL
** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define(‘YOURLS_UNIQUE_URLS’, true); 多个短网址对应同一个长地址,选true关闭该服务

/** Private means protected with login/pass as defined below. Set to false for public usage. */
define(‘YOURLS_PRIVATE’, true); 选择公开服务还是私有服务,一般都是自己用的吧,选true为私有

/** 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/cookie **/
define(‘YOURLS_COOKIEKEY’, ‘qQ4KhL_pu|s@Zm7n#%:b^{A[vhm’); 自定义cookie,不用改

/** Username(s) and password(s) allowed to access the site */
$yourls_user_passwords = array(
‘username’ => ‘password’, 将username和password分别替换为你登录yourls后台的用户名和密码
‘username2′ => ‘password2′ // You can have one or more ‘login’=>’password’ lines
); 可以设置多组,替换方法同上,安全起见只留一组最好

配置好后,将文件名修改为config.php,上传然后在浏览器中打开http://你的短网址/admin/install.php,按步骤即可,它的后台管理地址为:http://你的短网址/admin/,输入你所指定的一组账号密码即可登录(账号密码是以名文形式存放在你的config.php文件里的)。

做完这些工作后,我们就可以登陆生成我们自己的短网址了。另外,YOURLS还有基于wordpress的插件:YOURLS: WordPress to Twitter,大家也可以使用这个插件,令YOURLS与wordpress协同工作,官方网站有使用说明,非常详细。

最后,很多朋友使用VPS并用LNMP环境做站,这里再给出YOURLS伪静态规则。

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:属于自己的短网址
香港/美国/国内高速VPS
香港/美国/国内高速VPS