HackSoc / hacksoc.org

HackSoc website
https://www.hacksoc.org
8 stars 17 forks source link

Easy static redirects #121

Open LukeMoll opened 4 years ago

LukeMoll commented 4 years ago

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.