A secure, open-source link redirection service built on Cloudflare Pages Functions. Deploy it yourself and take full control of your link management with multiple encryption methods and comprehensive security features.
# Clone the repository
git clone https://github.com/your-username/link-redirect-service.git
# Navigate to the project directory
cd link-redirect-service
# Install Wrangler CLI globally
npm install -g wrangler
# Authenticate with Cloudflare
wrangler login
Create a .dev.vars file for local development and configure environment variables in the Cloudflare Pages dashboard for production:
GENERATE_PAGE_PASSWORD: Password for accessing the admin interfaceENCRYPTION_KEY: AES encryption key (recommended: 32+ characters, generate with openssl rand -base64 32)JWT_SECRET: JWT signing secret (recommended: 32+ characters, generate with openssl rand -base64 32)SESSION_TIMEOUT: Session timeout in seconds (default: 3600)DEFAULT_DELAY: Default delay time in milliseconds (default: 3000)ENABLE_REFERER_CHECK: Enable Referer checking (default: true)ENABLE_DELAY: Enable delayed redirection (default: true)ALLOWED_DOMAINS: Restrict target domains, comma-separated (e.g., example.com,test.org)ALLOWED_REFERERS: Restrict source domains, comma-separatedC_ENCRYPTION_KEY: AES encryption key for /c/ redirectsR_ENCRYPTION_KEY: AES encryption key for /r/ redirects# Run the development server
wrangler pages dev public
# Access the local development server at http://localhost:8788
# Deploy to production
wrangler pages deploy public --project-name=link-redirect-service
# Or deploy to a preview environment
wrangler pages deploy public --project-name=link-redirect-service --branch=preview
After deployment, you can configure a custom domain through the Cloudflare Pages dashboard:
For persistent click statistics, set up a Cloudflare KV namespace:
# Create KV namespace
wrangler kv:namespace create "REDIRECT_STATS"
# Update wrangler.toml to include the KV binding
# Add the following to wrangler.toml:
# [[kv_namespaces]]
# binding = "REDIRECT_STATS"
# id = "YOUR_KV_NAMESPACE_ID"
# preview_id = "YOUR_PREVIEW_KV_NAMESPACE_ID"
# Redeploy the project
wrangler pages deploy public
After successful deployment, access your service at the URL provided by Cloudflare Pages or your custom domain.
Pass parameters directly in the URL:
https://your-custom-domain.com/redirect?to=https://example.com&source=newsletter&delay=5000
Parameter description:
to: Target URL (required)source: Source identifier (optional)delay: Delay time in milliseconds (optional)Use the admin interface to create secure encrypted links:
https://your-custom-domain.com/loginGENERATE_PAGE_PASSWORDGenerated link format:
https://your-custom-domain.com/e/encrypted-dataThe admin interface allows you to:
Access the admin interface at https://your-custom-domain.com/generate (requires login).
.
├── functions/ # Cloudflare Pages Functions
│ ├── api/ # API routes
│ │ ├── login.js # Login API
│ │ ├── logout.js # Logout API
│ │ └── generate.js # Link generation API
│ ├── e/ # AES encrypted redirection
│ │ └── [[path]].js # Dynamic route
│ ├── lib/ # Utility library
│ │ └── utils.js # Common functions
│ ├── index.js # Home page
│ ├── login.js # Login page
│ ├── generate.js # Generation page
│ ├── redirect.js # Traditional redirection
│ └── health.js # Health check
├── public/ # Static files directory
├── wrangler.toml # Cloudflare configuration
└── README.md # Project documentation
GET / - Home page and usage instructionsGET /login - Login pagePOST /api/login - Login APIPOST /api/logout - Logout APIGET /generate - Link generation page (requires login)GET /api/generate - Link generation API (requires login)GET /redirect?to=URL - Traditional redirectionGET /e/{encrypted} - AES encrypted redirectionGET /health - Health checkGENERATE_PAGE_PASSWORDENCRYPTION_KEY and JWT_SECRETALLOWED_DOMAINS to limit target domainsALLOWED_REFERERS to limit sourcescontext object instead of env and ctxonRequest* functions for exports# Install dependencies
npm install wrangler -g
# Run locally
wrangler pages dev public
# Access http://localhost:8788
# Deploy to production
wrangler pages deploy public --project-name=link-redirect-service
# Deploy to preview environment
wrangler pages deploy public --project-name=link-redirect-service --branch=preview
GENERATE_PAGE_PASSWORD environment variable is correctly configuredENCRYPTION_KEY environment variable is configuredJWT_SECRET environment variable is configuredSESSION_TIMEOUT to increase session durationThis project is licensed under the MIT License. See the LICENSE file for details.
Copyright (c) 2026 Link Redirect Service
To keep your self-hosted instance up to date:
# Pull the latest changes
git pull origin main
# Redeploy the project
wrangler pages deploy public --project-name=link-redirect-service
Monitor your Cloudflare Pages deployment using:
WEBHOOK_URL)ALLOWED_DOMAINS to prevent abuseAs an open-source project, we welcome contributions from the community:
Please read our contributing guidelines before submitting contributions.
Join our community for support and discussions: