1. HOME
  2. 独自ドメインで短縮URLをつくる
2011.06.16 01:08

独自ドメインで短縮URLをつくる

Google URL Shortener(http://goo.gl/)やbitly(http://bit.ly/)など、URL短縮ツールは色々ありますが、遷移先の信憑性を高めるためにも、独自ドメインで実現したいですね。

そんな時に、使えるのがYOURLS(http://yourls.org/)です。

1.動作環境

PHP 4.3以降

MySQL 4.1以降

mod_rewriteが有効である

 

2.一式をダウンロード

http://code.google.com/p/yourls/downloads/list

より必要なファイル一式をダウンロードします。

 

3.ファイルを編集する

1.でダウンロードした /includes/config-sample.php を編集します。

 

/** MySQL database username */
define( 'YOURLS_DB_USER', 'dbuser' );

/** 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_' );

/*
 ** Site options
 */

/** YOURLS installation URL, no trailing slash */
define( 'YOURLS_SITE', 'http://hoge.com/yourls' );

DBユーザー名、パスワード、DB名、DBホスト、DBプレフィックス、サイトURLをそれぞれ自分の環境に合わせて入力します。

 

/**  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
	);



管理画面にログインする為の、ログインIDとパスワードを設定します。

入力し終わったら、config.phpという名前で保存します。

4.インストールする

ファイル一式をアップロード(今回は、http://hoge.com/yourls/にアップロード)し、

http://hoge.com/yourls/admin/

にアクセスすると、

yourls01.gif

インストール画面になるので、「Install YOURLS」ボタンをクリック。

yourls02.gif

すると、.htaccessが無い!と怒られるので、.htaccessを作ります。

5. .htaccessを配置

詳しくは、ここ(http://code.google.com/p/yourls/wiki/htaccess)に書いてあるのですが、

.htaccessに

RewriteEngine On
RewriteBase /yourls/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls/yourls-loader.php [L]

と記述して、配置します。

 

6.インストール完了

yourls03.gif

インストールが完了し、ログインすると上記のような画面が出てきます。

これで、簡単に独自ドメインで短縮URLが作れるようになりました。

 

 

先頭へ戻る