Nginx hashtag rewrite rule

南笙酒味 提交于 2019-12-08 08:56:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!