Nginx主题标签重写规则 [英] Nginx hashtag rewrite rule
问题描述
如何在nginx中使用正则表达式创建此rewrite
规则:
How can I create this rewrite
rule using regex in nginx:
http://www.example.com/my-path-here#hashvalue
到
http://www.example.com/my-path-here/#hashvalue 吗?
推荐答案
哈希标签是仅浏览器的概念,从不发送至服务器.因此,您不能在Nginx中重写.因为当您访问http://www.example.com/my-path-here#hashvalue
时,只会向http://www.example.com/my-path-here
Hash tags are a browser only concept and never sent to the server. So you can't rewrite then in nginx. Because when you visit http://www.example.com/my-path-here#hashvalue
the nginx server will only be sent http://www.example.com/my-path-here
您需要的是Javascript来为您处理此类事情.下面是一个示例html页面,
What you need is Javascript to handle such thing for you. Below is a sample html page which does that
<html>
<head>
<script>
var loc = window.location;
if (!loc.pathname.endsWith("/"))
loc.replace(loc.origin + loc.pathname + "/" + loc.hash);
</script>
</head>
<body>
<h1> You are here -
<script>
document.write(loc.href);
</script>
</h1>
</body>
</html>
这篇关于Nginx主题标签重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!