Git Product home page Git Product logo

redirector's Introduction

Redirector

A simple webserver that only redirects traffic based on a YAML configuration file.

Configuration

A sample configuration file is available in config.yaml. Each value can also be overridden with an environment variable.

---
bind_address: 0.0.0.0:8080
redirects:
  - rules.yaml

The bind address is the address and port that the HTTP server should listen to. The value can also be set by setting the BIND_ADDRESS environment variable.

The redirects array is evaluated in the order that files appear in the list. Files can be local or remote (http and https only for now). The environment variable REDIRECT_SOURCE can also be used, with multiple values separated by commas.

Redirect Rules

Each redirect rule has a name, a match pattern, and one or more targets.

To redirect blahblahblah.com (with an optional leading www) to somethingdifferent.com using a 301 redirect you would use

- name: Blah Test
  pattern: ^(www\.)?blahblahblah.com\/
  targets:
  - target: https://somethingdifferent.com/
    code: 301

By Source IP

You can get more complex and redirect based on the source IP address (as reported in the X-Forwareded-For header) too:

- name: TV
  pattern: ^tv\.university\.edu/
  targets:
  - target: https://contour.university.edu
    code: 302
    when:
      source:
        - 10.0.0.0/8
        - 192.168.1.0/24
  - target: https://google.com
    code: 302

The above example essentially says redirect tv.university.edu to contour.university.edu when inside one of the two source IP ranges, otherwise redirect to google.com. Whenever multiple targets are used you should use 302 redirects to avoid browsers caching the redirects.

Substitutions

Because everything is stored as regular expressions, substitutions are also possible:

- name: All to SSL
  pattern: ^(www\.)?(?P<name>[a-zA-Z0-9\-]+).com\/
  targets:
  - target: https://${name}.university.edu/
    code: 301

Fall Back

Regular expressions are evaluated in the order they appear in the configuration file. You should consider having some sort of catch all resource at the bottom to prevent dead end 404s.

Reloading

Redirect rules can be reloaded without restarting the application by sending an HTTP GET request to /reload.

Docker

Everything should work well under Docker without having to modify the base image (using remote redirect rules with environment variables). An image is available on the hub at pcfens/redirector.

redirector's People

Contributors

pcfens avatar

Stargazers

gurpal2000 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.