Amazon KDP Marketplace Redirect for YOURLS

Installation

  1. Place the sebstr_amazon_kdp directory in user/plugins on the development YOURLS installation.
  2. Activate Amazon KDP Marketplace Redirect in Manage Plugins.
  3. Open Amazon KDP in the administration menu. Enter an ASIN and an optional title, then select Save ASIN. Saving the same ASIN updates its title. Use Remove to unregister an edition.
  4. Shorten a standard Amazon product URL as usual. Register each edition's ASIN separately, including left-handed editions. Registration applies to existing and future short links across all source marketplaces in the table.

The registry uses the YOURLS option sebstr_amazon_kdp_asins. Short-link destination records retain the original URLs. The plugin targets YOURLS 1.10.6 and PHP 8.4 or newer.

Redirect behaviour

The plugin recognises ten-character ASINs in Amazon /dp/, /gp/product/, and /gp/aw/d/ product URLs. It matches only the marketplace hosts below, including their www. and m. variants. Explicit seller and offer URLs take precedence, including URLs with a merchant or seller parameter such as smid and URLs containing the legacy seller plugin's cx_skuctr_share marker.

For a registered edition, the same-marketplace and unavailable-country cases use the stored URL verbatim. Cross-marketplace redirects use a standard HTTPS product URL with the same ASIN and original fragment. Query parameters retain their original encoding and order, and the first occurrence of a repeated name is used for the rewritten URL. Amazon controls whether a parameter such as an affiliate tag has meaning on the destination marketplace.

Only eligible registered links bypass the legacy Amazon seller callback. YOURLS runs its usual click counter and detailed logging once per origin request, subject to its statistics settings, and then sends the 302. The plugin works with the seller plugin enabled or disabled.

Cloudflare

Enable IP Geolocation for the dev zone. The origin's PHP REMOTE_ADDR must identify the Cloudflare peer for geolocation to work. If a reverse proxy or real-IP module replaces it with the visitor address, the plugin uses the original URL. Forwarded IP headers are ignored for this trust decision. The bundled IPv4 and IPv6 ranges come from Cloudflare's published lists and should be updated when those lists change. IP Geolocation · Cloudflare IP ranges

Eligible redirects send Cache-Control: private, no-store, max-age=0 and Cloudflare-CDN-Cache-Control: no-store, including fallback redirects. If a zone rule overrides origin cache headers, set a Cache Rule to bypass caching for YOURLS short-link requests. Purge any previously cached redirects for those paths. A browser may retain a permanent redirect issued before activation until its local cache is cleared or expires. Cloudflare default cache behaviour · Cloudflare CDN cache-control headers

Marketplace mapping

Country Marketplace Country Marketplace
AU amazon.com.au BE amazon.com.be
BR amazon.com.br CA amazon.ca
DE amazon.de ES amazon.es
FR amazon.fr GB amazon.co.uk
IE amazon.ie IN amazon.in
IT amazon.it JP amazon.co.jp
MX amazon.com.mx NL amazon.nl
PL amazon.pl SE amazon.se
US amazon.com

The mapping includes marketplaces listed across Amazon's KDP print and Kindle documentation. Availability varies by edition, format, and distribution rights. For example, Brazil and Mexico support KDP eBooks, and Amazon has announced that Kindle eBook purchases on Amazon.in end on 26 February 2027. Review the India mapping before that transition. The plugin does no Amazon availability lookup, so a mapped marketplace may show an unavailable product if the edition is unavailable there. KDP print distribution · KDP eBook distribution · India Kindle changes

Automated tests

In a YOURLS installation with the existing seller plugin at user/plugins/sebstr_amazon, run php user/plugins/sebstr_amazon_kdp/tests/run.php from the YOURLS root. The suite uses PHP CLI and php-cgi. It loads the real YOURLS redirect and hook functions with isolated registry and statistics fixtures. It makes no database or network calls.

Release package

Build the installable ZIP from the tagged commit:

git archive --format=zip --prefix=sebstr_amazon_kdp/ \
  -o sebstr_amazon_kdp-1.0.0.zip v1.0.0

Extract the ZIP under the target installation's user/plugins directory. The package contains the plugin PHP files and this README. Register the edition ASINs in YOURLS admin on the target installation.

S
Description
No description provided
Readme MIT
40 KiB
0 Stars 1 Watchers 0 Forks
2026-12-03 11:01:59 +00:00
Languages
PHP 100%