In my website blog pages added query string in that page URL. I wanted to remove the query string from the URL. So i used to go with jquery and i wrote and added into my scripts. It removes the query string but keep on refreshing the page upto nth time. I used to "one" jquery method. That also doesn't work.
Can you help me
My Script is
jQuery(document).one('ready',function(){
window.location.href = window.location.href.split('?')[0];
});
To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.
delete() The delete() method of the URLSearchParams interface deletes the given search parameter and all its associated values, from the list of all search parameters.
Why remove query strings? Main two reasons for this. 1. Clear URL alwaya look better than the long URL 2. When you are not remove your query string from URL. then all get variable show in you URL string. sometime it not good for a security
W3 Total Cache plugin offers an option to remove query strings from static resources. You only need to UNCHECK (if already checked) an option and it will remove query strings from 90% of the URLs. Steps to Remove Query Strings from URL with WordPress plugin Install and Activate the W3 Total Cache Plugin.
Query Strings can be removed by using a WordPress plugin called Remove Query Strings From Static Resources. I would recommend this method to beginners, who don’t want to mess up with coding stuff. Install and activate this plugin. There is no setting panel, so just activation of the plugin will do the trick.
Query Strings are the URLs that contain “?” or “&”. for example, technumero.com/script.js?ver=1.6 It is similar to the CSS and JS files of your website, which usually have the file version at the end of their URLs. Therefore, these query string resources would be the resource URLs with a “?” or “&”.
var uri = window.location.href.toString();
if (uri.indexOf("?") > 0) {
var clean_uri = uri.substring(0, uri.indexOf("?"));
window.history.replaceState({}, document.title, clean_uri);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With