Nginx主题标签重写规则 [英] Nginx hashtag rewrite rule

查看:75
本文介绍了Nginx主题标签重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆