I need to hide the full URL extensions of my website

1.1k Views Asked by At

I would like to mask the URL extensions of my website.

If the name of my website is: mywebsite. I have various content pages on my site such as: contentpage1.html or contentpage2.html

Normally, when a content page is opened, the browser address bar displays:

mywebsite.com/contentpage1.html or mywebsite.com/contentpage1.html

Is there a way to mask that, so no matter what pages are being viewed on my site, ONLY the root URL mywebsite.com and nothing more is always shown in the address bar?

2

There are 2 best solutions below

1
Liwu On BEST ANSWER

This is simplier as you think. This is my case, just try this:

(function hideMyURL() {
    var re = new RegExp(/^.*\//);
    window.history.pushState("object or string", "Title", re.exec(window.location.href));
})();

Is it this what you're looking for?

0
Ashland Simpson On

Use JavaScript's history.pushState() or history.replaceState() functions. This might help you out.

https://developer.mozilla.org/en-US/docs/Web/API/History_API