Link Redirect Service - Open Source Self-Hosted Version

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.

Key Features

Self-Deployment Guide

1. Prerequisites

2. Get the Source Code

# Clone the repository
git clone https://github.com/your-username/link-redirect-service.git

# Navigate to the project directory
cd link-redirect-service

3. Install Wrangler CLI

# Install Wrangler CLI globally
npm install -g wrangler

4. Login to Cloudflare

# Authenticate with Cloudflare
wrangler login

5. Configure Environment Variables

Create a .dev.vars file for local development and configure environment variables in the Cloudflare Pages dashboard for production:

Required Variables

Optional Variables for Self-Deployment

6. Test Locally (Optional)

# Run the development server
wrangler pages dev public

# Access the local development server at http://localhost:8788

7. Deploy to Cloudflare Pages

# 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

8. Configure Custom Domain (Optional)

After deployment, you can configure a custom domain through the Cloudflare Pages dashboard:

  1. Go to your Cloudflare Pages project
  2. Click on "Custom domains" in the left sidebar
  3. Click "Set up a custom domain"
  4. Follow the instructions to add your domain and configure DNS records

9. Configure KV Namespace for Persistent Statistics (Optional)

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

Usage

1. Access Your Deployed Service

After successful deployment, access your service at the URL provided by Cloudflare Pages or your custom domain.

2. Traditional Redirection (Unencrypted)

Pass parameters directly in the URL:

https://your-custom-domain.com/redirect?to=https://example.com&source=newsletter&delay=5000

Parameter description:

3. Encrypted Redirection

Use the admin interface to create secure encrypted links:

  1. Visit https://your-custom-domain.com/login
  2. Enter the password you configured in GENERATE_PAGE_PASSWORD
  3. Fill in the target URL and optional parameters on the generation page
  4. Click to generate the encrypted link

Generated link format:

4. Admin Interface

The admin interface allows you to:

Access the admin interface at https://your-custom-domain.com/generate (requires login).

Project Structure

.
├── 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

API Endpoints

Security Recommendations

  1. Strong Password: Use a strong password for GENERATE_PAGE_PASSWORD
  2. Key Management: Regularly rotate ENCRYPTION_KEY and JWT_SECRET
  3. Domain Restrictions: Configure ALLOWED_DOMAINS to limit target domains
  4. Referer Checks: Configure ALLOWED_REFERERS to limit sources
  5. HTTPS: Ensure the service is accessed over HTTPS
  6. Log Monitoring: Regularly check logs for abnormal access

Differences from Workers Version

Advantages of Cloudflare Pages Functions

  1. File System Routing: More intuitive route structure
  2. Static Assets: Can directly host static files
  3. Automatic Deployment: Git integration with automatic deployment
  4. Free Tier: Higher free request quota

Major Changes

  1. Routing Method: Changed from single entry to file system routing
  2. Context Object: Uses context object instead of env and ctx
  3. Export Method: Uses onRequest* functions for exports
  4. Modularization: Better code organization and modularity

Development

Local Development

# Install dependencies
npm install wrangler -g

# Run locally
wrangler pages dev public

# Access http://localhost:8788

Deployment

# 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

Troubleshooting

1. Login Failure

2. Encrypted Link Inaccessible

3. JWT Session Expired

License

This project is licensed under the MIT License. See the LICENSE file for details.

Copyright (c) 2026 Link Redirect Service

Maintenance & Updates

Updating Your Deployment

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

Monitoring Your Deployment

Monitor your Cloudflare Pages deployment using:

Security Best Practices for Self-Deployment

  1. Regular Updates: Keep your deployment updated with the latest security patches
  2. Strong Passwords: Use a strong password for the admin interface
  3. Secure Keys: Use unique, randomly generated encryption keys and JWT secrets
  4. Domain Restrictions: Configure ALLOWED_DOMAINS to prevent abuse
  5. HTTPS Only: Ensure your custom domain uses HTTPS with a valid SSL certificate
  6. Monitor Usage: Regularly check logs for unusual activity

Contributing to the Project

As an open-source project, we welcome contributions from the community:

  1. Report Issues: Submit bug reports and feature requests on GitHub Issues
  2. Submit Pull Requests: Contribute code improvements and new features
  3. Improve Documentation: Help us improve this documentation
  4. Share Feedback: Let us know how we can improve the service

Please read our contributing guidelines before submitting contributions.

Community Support

Join our community for support and discussions: