简体   繁体   English

当用户重定向到页面时隐藏 url 中的查询字符串

[英]Hide query string from url when user redirects to page

I am currently using webflow to host my site.我目前正在使用 webflow 来托管我的网站。 In the redirection section on the hosting tab.在托管选项卡上的重定向部分。 I added a 301 redirect query string that redirects to my index, I do this because I wanted to track where do the users come from in my site.我添加了一个重定向到我的索引的 301 重定向查询字符串,我这样做是因为我想跟踪用户来自我网站的哪里。

Read this article and try it out: https://www.newmediacampaigns.com/blog/how-to-track-landing-page-redirects-using-google-analytics阅读这篇文章并尝试一下: https : //www.newmediacampaigns.com/blog/how-to-track-landing-page-redirects-using-google-analytics

So basically it states this:所以基本上它说明了这一点:

  • old path: /mexico旧路径:/mexico
  • new path: example.com/?key=mexico新路径:example.com/?key=mexico

So for example i created a redirect /mexico to go to my index with a query string.例如,我创建了一个重定向 /mexico 以使用查询字符串转到我的索引。 Currently it works really well, but i want to know if it is possible that the user does not see the query string when entering from a redirect link.目前它工作得很好,但我想知道用户是否有可能在从重定向链接输入时看不到查询字符串。

For example when user enters by example.com/mexico, the url search bar shows only example.com例如当用户通过example.com/mexico输入时,url搜索栏只显示example.com

I tried hiding it using javascript, but does not work.我尝试使用 javascript 隐藏它,但不起作用。

    var testURL = 'myurl';
    testURL.split('?')[0]; 

Any clue?有什么线索吗? or suggestion?或建议?

The only way to do this is with thehistory API - not available in older browsers.做到这一点的唯一方法是使用历史 API - 在旧浏览器中不可用。

The standard way of doing this is这样做的标准方法是

history.pushState("object or state to represent your page", "page title", "/thenewurlpath");

You could add this to your document.ready callback, EG您可以将此添加到您的document.ready回调中,EG

$(document).ready(function(){
  history.pushState("something", "newtitle", "/thenewpath");
  // Whatever else your document.ready callback is doing...
})

Hope this helped :)希望这有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户重新加载页面时,删除网址中的查询字符串 - Remove query string in url when user reloads page 页面跳转时从URL隐藏哈希 - Hide hash from URL when page jump 当用户单击页面1上的按钮时,它将数据发送到页面2并重定向到页面3 - When a user clicks a button on page 1 it sends data to page 2 and redirects to page 3 从字段重定向查询字符串的简单表单 - Simple form that redirects with query string from field 页面重定向时,如何从 webview 获取 url? (这是一个功能组件而不是类) - How can I get the url from webview when page redirects? (This is in a functional component not class) 从URL中获取用户名,然后使用带有该用户名的查询字符串进行重定向 - Take the user name from the URL and redirect with a query string with that user name jQuery-将查询字符串添加到URL时的页面循环 - Jquery - page looping when adding a query string to the URL 当JS重定向到其他页面时,Chrome显示URL - Chrome shows URL, when JS redirects to other page 从浏览器网址中删除查询字符串,而无需重新加载页面 - Strip query string from browser url without reloading page 将URL查询字符串参数从页面传递到Wordpress中的iFrame - Pass URL query string parameters from page to iFrame in Wordpress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM