我怎样才能使用'#'而不是“?”使用 mod_rewrite

发布于 2024-12-23 23:07:18 字数 184 浏览 3 评论 0原文

我在网站上使用 js 来加载页面,而无需重新加载布局。由于可以在 Facebook 上共享链接,我必须将参数显示为哈希(我不能将参数作为查询字符串给出,否则页面将重新加载)。如何将 mywebsite.com/#query=string 重写为 mywebsite.com/?query=string

I use js on my website to load pages without reloading the layout. Because of the possibility of sharing the links on facebook, I had to show the params as a hash (i cant give the params as query string, otherwise the page will be reloaded). How can i rewrite mywebsite.com/#query=string to mywebsite.com/?query=string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

许你一世情深 2024-12-30 23:07:18

您不能,因为 URL 片段永远不会发送到服务器。您将需要使用 XHR 从服务器加载适当的内容。

You can't, since the URL fragment is never sent to the server. You will need to use XHR to load the appropriate content from the server.

我们只是彼此的过ke 2024-12-30 23:07:18

你的服务器永远不会看到哈希部分,浏览器不会将其作为 HTTP 请求的一部分发送,所以你不可能使用 mod_rewrite 来做到这一点。

Your server will never see the hash part, browsers don't send that as part of HTTP request, so no way you'd do that with mod_rewrite.

£烟消云散 2024-12-30 23:07:18

除了之前所说的:

    <script type="text/javascript">
        var url = window.location.href ;           
        var pos = url.indexOf('#');
        if(pos!=-1){
            var addition = url.substring(pos);
            alert(addition);
            //do ajax request with 'addition' parameter value
        }
    </script>

In addition to all saying earlier :

    <script type="text/javascript">
        var url = window.location.href ;           
        var pos = url.indexOf('#');
        if(pos!=-1){
            var addition = url.substring(pos);
            alert(addition);
            //do ajax request with 'addition' parameter value
        }
    </script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文