项目作者: DannyBen

项目描述 :
Redirect server with dynamic URL and hostname support
高级语言: Ruby
项目地址: git://github.com/DannyBen/redirectly.git
创建时间: 2021-07-05T11:47:17Z
项目社区:https://github.com/DannyBen/redirectly

开源协议:MIT License

下载


Redirectly - Redirect server with dynamic URL and hostname support

Gem Version
Build Status
Maintainability


Redirectly is a simple URL redirect server that uses a simple INI file for
defining dynamic redirects.


Install

  1. $ gem install redirectly

Docker Image

Redirectly is also available as a docker image:

  1. # Pull the image
  2. $ docker pull dannyben/redirectly
  3. # Run the redirectly command line
  4. $ docker run --rm -it dannyben/redirectly --help
  5. # Start the server with your local configuration file
  6. $ docker run --rm -it \
  7. -p 3000:3000 \
  8. -v $PWD/redirects.ini:/app/redirects.ini \
  9. dannyben/redirectly

Using with docker-compose

  1. # docker-compose.yml
  2. services:
  3. redirectly:
  4. image: dannyben/redirectly
  5. ports:
  6. - 3000:3000
  7. volumes:
  8. - ./redirects.ini:/app/redirects.ini

Using as an alias

  1. $ alias redirectly='docker run --rm -it -p 3000:3000 -v $PWD/redirects.ini:/app/redirects.ini dannyben/redirectly'

Quick Start

  1. # In an empty directory, create a sample configuration file
  2. $ redirectly --init
  3. # Start the server
  4. $ redirectly
  5. # In another terminal, access the server using one of the configured rules
  6. $ curl -v something.localhost:3000

You should receive a redirect header:

  1. # ...
  2. < HTTP/1.1 302 Found
  3. < Location: http://it-works.com/something
  4. # ...

Usage

Redirectly requires a simple INI file with redirect configuration details.

You can create a sample configuration file by running:

  1. $ redirectly --init

This will create a sample redirects.ini file:

  1. example.com = https://other-site.com/
  2. *.mygoogle.com/:anything = https://google.com/?q=%{anything}
  3. example.org/* = https://other-site.com/
  4. *.old-site.com = !https://permanent.redirect.com
  5. :sub.app.localhost/* = http://it-works.com/%{sub}
  6. proxy.localhost/*rest = @https://proxy.target.com/base/*rest
  7. internal.localhost/reload = :reload
  8. (*)old-domain.com/*rest = http://new-domain.com/%{rest}

For additional server options, see:

  1. $ redirectly --help

The configuration file is built of pattern = target pairs, where:

  • pattern - is any URL pattern that is supported by Mustermann.
  • target - is the target URL to redirect to.

Special INI Notation

Redirect type

If the target starts with !, a permanent redirect (301) will be performed.
If it does not, a temporary redirect (302) will be performed by default:

  1. test.localhost/temporary = http://example.com
  2. test.localhost/permanent = !http://example.com

Proxying

If the target starts with @, the content will be proxied instead of being
redirected:

  1. test.localhost = @http://example.com

Named arguments

Patterns that include strings starting with a colon : will expose those
strings as Ruby substitution variables in the target:

  1. test.localhost/:anything = http://example.com/path/%{anything}

Splats

You can use a splat * or a named splat *name in the pattern.
Named splats will also be exposed as Ruby substitution variables in the target:

  1. (*)test.localhost/*rest = http://example.com/%{rest}

Contributing / Support

If you experience any issue, have a question or a suggestion, or if you wish
to contribute, feel free to open an issue.