Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy static redirects #121

Open
LukeMoll opened this issue Oct 29, 2020 · 0 comments
Open

Easy static redirects #121

LukeMoll opened this issue Oct 29, 2020 · 0 comments
Labels
backend Relating to the code which runs on the server and generates the site enhancement

Comments

@LukeMoll
Copy link
Member

Idea

With a simple context file (eg templates/redirect.yaml), have a mapping of names (foo) to redirect URLs (https://foo.com/hacksoc). This would be useful for having branded, memorable links for services like Discord invites, mailing list Google Form, etc.


Implementation

Here are two ways this could be implemented:

1.

A mapping foo to https://foo.com/hacksoc generates a file called foo, with the contents

<html>
    <head>
        <meta http-equiv="refresh" content="0;URL='https://foo.com/hacksoc'" /> 
    </head>
    <body>
        <p>You are being redirected to <a href="https://foo.com/hacksoc">https://foo.com/hacksoc</a></p>
    </body>
</html>

Correct operation depends on nginx serving extension-less files as text/html – if needed redirects could be served under hacksoc.org/redir/foo (for example), and then Content-type rules could be applied to the /redir/ path.

2. HTTP 302

A mapping foo to https://foo.com/hacksoc generates a nginx config block, with the contents

location /foo {
    return 302 https://foo.com/hacksoc;        
}

All of the nginx config blocks are written to redirect.conf, which is placed somewhere outside of the webroot.

  • The main nginx server block for www.hacksoc.org has include /path/to/redirect.conf; in an appropriate place
  • The webhook which is triggered when the repository is pushed to includes a call to systemctl reload nginx or nginx -s reload
  • The user which runs the webhook is allowed to run the above commands (eg via sudoers)
@LukeMoll LukeMoll added enhancement backend Relating to the code which runs on the server and generates the site labels Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Relating to the code which runs on the server and generates the site enhancement
Projects
None yet
Development

No branches or pull requests

1 participant