I tried to redirect to homepage by adding this meta tag inside 404.html file :
JavaScript
x
5
1
<meta
2
http-equiv="refresh"
3
content="0; URL='https://gittestfor.github.io'"
4
/>
5
And it works fine the first time but the second the page gets cached it doesn’t work .
When I clear site data in the application tab in developer console , it works .
How can I disable this behaviour or redirect from any path to homepage “/” with github pages ?
Advertisement
Answer
I solved the issue by adding a 404.html file to the root of the project in github pages repo and added this code to that file :
JavaScript
1
13
13
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8" />
5
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
<meta
7
http-equiv="refresh"
8
content="0; URL='https://username.github.io'"
9
/>
10
</head>
11
<body></body>
12
</html>
13
Now every request other than https://username.github.io/
like .../name
will be redirected to the homepage which is /
.
Note : This behaviour works only when the page is not cached in the browser and there is no service worker to cache the website .