如何将所有文件夹重定向到我的 index.html 并确定用户来自何处。
首先,我只有 index.html
和 .htaccess
文件。
场景:
- 用户点击链接:
mydomain.com/blabla
(通常转到 404) - 网站重定向到用户
mydomain.com/index.html
或mydomain.com/index.html?par=blabla
- 在
mydomain.com/index.html
中显示警报“来自mydomain.com/blabla
”
这可能吗?谢谢。
更新************
我找到了这样的解决方法。
首先更改.htaccess 文件:https://stackoverflow.com/a/21663207/1173413
并使用 alert(window.location);
正如 Polostor 所说。
最佳答案
我可以想象这样的事情。
文件 .htaccess 重定向页面并将最后一页设置为 getter。当 .htaccess 位于主文件夹中时,它适用于任何子文件夹。
<罢工>罢工>
<罢工>RewriteEngine on
RewriteRule ^(.*) /index.html?page=$1 [R=301,L]
罢工><罢工>罢工> 编辑:更好的解决方案应该是 https://stackoverflow.com/a/12500251/4745695
规则是
- R 代表响应代码为 301 的重定向
- L 表示这是最后一条规则
在 index.html 中它会是这样的。
<html>
<head>
<title>My title</title>
<script>
alert(window.location.search.substring(1));
</script>
</head>
<body>
</body>
</html>
我从 How to get the value from the GET parameters?(分别为 location.search in javascript)获取了 get 方法,并且 .htaccess 在 http://www.jakpsatweb.cz/server/ 的那些页面上有很好的描述(在捷克语中,使用谷歌翻译器翻译它们)。
关于javascript - 将所有 html 页面和文件夹重定向到 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29990911/