简体   繁体   中英

Hide query string from url when user redirects to page

I am currently using webflow to host my site. 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.

Read this article and try it out: https://www.newmediacampaigns.com/blog/how-to-track-landing-page-redirects-using-google-analytics

So basically it states this:

  • old path: /mexico
  • new path: example.com/?key=mexico

So for example i created a redirect /mexico to go to my index with a query string. 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

I tried hiding it using javascript, but does not work.

    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.

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(function(){
  history.pushState("something", "newtitle", "/thenewpath");
  // Whatever else your document.ready callback is doing...
})

Hope this helped :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM