Skip to content

khaliduzzamantanoy/Pyredirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ PyRedirect

PyRedirect Logo

A powerful, lightweight Flask application for intelligent URL redirection πŸ”„

Python Flask Docker License GitHub Stars GitHub Forks


Seamlessly redirect all incoming requests while preserving path structures with enterprise-grade reliability ✨

πŸš€ Quick Start β€’ πŸ“– Documentation β€’ 🐳 Docker


✨ Features

🎯 Universal Redirect

Redirect all incoming requests to any external URL with zero configuration hassle

πŸ›€οΈ Path Preservation

Maintains original URL structure - no broken links, no lost paths

πŸ“Š Smart Logging

Built-in request logging with timestamps for monitoring and analytics

🐳 Docker Ready

Production-ready containerization with security best practices

⚑ Production Grade

Gunicorn WSGI server configuration for high-performance deployment

πŸ”’ Security First

Non-root user execution and secure container practices


πŸš€ Quick Start

πŸ’» Local Development

# πŸ“₯ Clone the repository
git clone https://github.com/khaliduzzamantanoy/Pyredirect.git
cd Pyredirect

# πŸ“¦ Install dependencies
pip install -r requirements.txt

# βš™οΈ Configure your redirect URL (edit app.py)
# Replace 'https://your-redirect-url/' with your target

# 🎯 Run the application
python app.py

🌐 Access your app at: http://localhost:5000

🐳 Docker Deployment

# πŸ”¨ Build the Docker image
docker build -t pyredirect .

# πŸš€ Run the container
docker run -p 5002:5002 pyredirect

🌐 Access your app at: http://localhost:5002


βš™οΈ Configuration

🎯 Setting Up Your Redirect URL

πŸ“ Click to expand configuration details

Edit the catch_all function in app.py:

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    # πŸ”„ Replace with your target URL
    return redirect(f'https://your-awesome-site.com/{path}', code=302)

πŸ“Š Logging Configuration

Feature Status Description
πŸ“ Request Logging βœ… Enabled Logs all incoming requests with timestamps
πŸ”‡ Disable Logging βš™οΈ Optional Comment out @app.before_request decorator
πŸ“ˆ Custom Logging πŸ› οΈ Extensible Add your own logging logic

πŸ”Œ Port Configuration

Environment Port Description
🏠 Development 5000 Default Flask development server
🐳 Docker 5002 Container exposed port
🏭 Production 5002 Gunicorn WSGI server

πŸ“– How It Works

graph TD
    A[🌐 Incoming Request] --> B[πŸ” Flask Catch-All Route]
    B --> C[πŸ“ Log Request]
    C --> D[πŸ›€οΈ Extract Path]
    D --> E[πŸ”„ Generate Redirect URL]
    E --> F[↩️ HTTP 302 Redirect]
    
    style A fill:#e1f5fe
    style F fill:#f3e5f5
Loading

🎯 Example Redirections

Original URL Redirects To Status
yourapp.com/ example.com/ βœ…
yourapp.com/about example.com/about βœ…
yourapp.com/api/users/123 example.com/api/users/123 βœ…
yourapp.com/blog/post?id=5 example.com/blog/post?id=5 βœ…

πŸ“ Project Structure

πŸ—‚οΈ Pyredirect/
β”œβ”€β”€ 🐍 app.py              # Main Flask application
β”œβ”€β”€ 🌐 wsgi.py             # WSGI entry point  
β”œβ”€β”€ 🐳 Dockerfile          # Docker configuration
β”œβ”€β”€ πŸ“¦ requirements.txt    # Python dependencies
└── πŸ“– README.md          # You are here!

πŸ› οΈ Dependencies

Package Version Purpose
Flask 2.x Web framework for HTTP handling
Gunicorn 21.x Production WSGI server

🏭 Production Deployment

πŸš€ Manual Deployment

# πŸ“¦ Install production server
pip install gunicorn

# 🏭 Run in production mode
gunicorn --bind 0.0.0.0:5002 app:app

πŸ”§ Advanced Configuration

πŸ› οΈ Advanced Gunicorn Settings
# πŸš€ High-performance configuration
gunicorn --bind 0.0.0.0:5002 \
         --workers 4 \
         --timeout 30 \
         --keep-alive 2 \
         --max-requests 1000 \
         app:app

πŸ›‘οΈ Security Features

Security Feature Status Description
πŸ‘€ Non-root User βœ… Container runs as unprivileged user
πŸ”’ Minimal Base Image βœ… Python slim image reduces attack surface
🚫 No Root Privileges βœ… Application runs with limited permissions
πŸ“Š Request Monitoring βœ… Built-in logging for security analysis

🎯 Use Cases

🌟 Perfect For:

Use Case Description Benefits
🏠➑️🏒 Domain Migration Redirect from old to new domain SEO preservation, seamless transition
🚧 Maintenance Mode Redirect during site maintenance User experience continuity
βš–οΈ Load Balancing Simple traffic distribution High availability, performance
πŸ”— URL Shortening Base for shortening services Scalable, customizable
πŸ§ͺ A/B Testing Traffic splitting for testing Data-driven decisions

🎨 Customization Examples

🌈 Custom Redirect Logic

πŸ’‘ Advanced Redirect Patterns
@app.route('/<path:path>')
def smart_redirect(path):
    # 🎯 Conditional redirects based on path
    if path.startswith('api/'):
        return redirect(f'https://api.example.com/{path[4:]}', code=302)
    elif path.startswith('blog/'):
        return redirect(f'https://blog.example.com/{path[5:]}', code=302)
    else:
        return redirect(f'https://main.example.com/{path}', code=302)

πŸ“Š Enhanced Logging

πŸ“ˆ Advanced Logging Setup
import logging
from datetime import datetime

# πŸ“ Setup enhanced logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@app.before_request
def enhanced_logging():
    logger.info({
        'timestamp': datetime.now().isoformat(),
        'method': request.method,
        'url': request.url,
        'user_agent': request.user_agent.string,
        'remote_addr': request.remote_addr
    })

πŸ“„ License

This project is licensed under the MIT License πŸ“œ

License: MIT

Feel free to use, modify, and distribute this project ✨


πŸ†˜ Support & Community

Resource Link Description
πŸ› Issues GitHub Issues Bug reports & feature requests
πŸ’¬ Discussions GitHub Discussions Community support & ideas
πŸ“§ Contact Create Issue Direct support

⭐ Star this repo if you find it useful!

GitHub stars


Made with ❀️ by Khaliduzzaman Tanoy

PyRedirect - Simplifying URL redirection, one request at a time πŸš€


⚠️ Important: Remember to replace https://your-redirect-url/ in your code with your actual target URL before deployment!

About

A lightweight Flask application that redirects all incoming requests to a specified external URL while preserving the original path structure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors