Skip to content

Commit f699759

Browse files
Handle 404 redirect
1 parent 4d73686 commit f699759

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

public/404.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Cypherpunks CTF</title>
6+
<script type="text/javascript">
7+
// Single Page Apps for GitHub Pages
8+
// https://github.com/rafrex/spa-github-pages
9+
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
10+
// ----------------------------------------------------------------------
11+
// This script takes the current url and converts the path and query
12+
// string into just a query string, and then redirects the browser
13+
// to the new url with only a query string and hash fragment,
14+
// e.g. http://www.foo.tld/one/two?a=b&c=d#qwe, becomes
15+
// http://www.foo.tld/?p=/one/two&q=a=b~and~c=d#qwe
16+
// Note: this 404.html file must be at least 512 bytes for it to work
17+
// with Internet Explorer (it is currently > 512 bytes)
18+
// If you're creating a Project Pages site and NOT using a custom domain,
19+
// then set segmentCount to 1 (enterprise users may need to set it to > 1).
20+
// This way the code will only replace the route part of the path, and not
21+
// the real directory in which the app resides, for example:
22+
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
23+
// https://username.github.io/repo-name/?p=/one/two&q=a=b~and~c=d#qwe
24+
// Otherwise, leave segmentCount as 0.
25+
var segmentCount = 1;
26+
var l = window.location;
27+
l.replace(
28+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
29+
l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?p=/' +
30+
l.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') +
31+
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
32+
l.hash
33+
);
34+
</script>
35+
</head>
36+
<body>
37+
</body>
38+
</html>

public/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@
77
<link rel="shortcut icon" href="%PUBLIC_URL%/imgs/favicon.ico">
88
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
99
<title>Cypherpunks CTF</title>
10+
<script type="text/javascript">
11+
// Single Page Apps for GitHub Pages
12+
// https://github.com/rafrex/spa-github-pages
13+
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
14+
// ----------------------------------------------------------------------
15+
// This script checks to see if a redirect is present in the query string
16+
// and converts it back into the correct url and adds it to the
17+
// browser's history using window.history.replaceState(...),
18+
// which won't cause the browser to attempt to load the new url.
19+
// When the single page app is loaded further down in this file,
20+
// the correct url will be waiting in the browser's history for
21+
// the single page app to route accordingly.
22+
(function(l) {
23+
if (l.search) {
24+
var q = {};
25+
l.search.slice(1).split('&').forEach(function(v) {
26+
var a = v.split('=');
27+
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&');
28+
});
29+
if (q.p !== undefined) {
30+
window.history.replaceState(null, null,
31+
l.pathname.slice(0, -1) + (q.p || '') +
32+
(q.q ? ('?' + q.q) : '') +
33+
l.hash
34+
);
35+
}
36+
}
37+
}(window.location))
38+
</script>
1039
</head>
1140

1241
<body>

0 commit comments

Comments
 (0)