あなたの質問は、むしろ YOURLS バックエンドを対象としています。YOURLS の最新バージョンを使用している場合、デフォルトで短い URL が重複しないことを確認できます。長い URL を複数回送信しても、API は同じ短い URL を (Javascript クライアントに) 返します。
その設定は、config.php
YOURLS サーバーの にあります。
/** 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
ください。
開始するのに役立つように、Javascript を使用して短い URL を作成する簡単な方法を次に示します。YOURLSにはこのサードパーティのラッパーを使用しています。
ユーザー名/パスワード、または署名トークンを使用してサーバーに接続する必要があります。
var api = yourls.connect('http://your.server/yourls-api.php', {
username: 'admin',
password: 'qwerty'
});
接続が確立されている場合は、次を使用できます.shorten()
。
api.shorten('https://yourverylonglink.com/toshorten', function(data) {
console.log(data.shorturl); // returns http://your.server/1234
});