问题
How can I create this rewrite
rule using regex in nginx:
http://www.example.com/my-path-here#hashvalue
to
http://www.example.com/my-path-here/#hashvalue ?
回答1:
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
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>
来源:https://stackoverflow.com/questions/46055093/nginx-hashtag-rewrite-rule