Skip to content Skip to sidebar Skip to footer

Removing '#' From Url Using Htaccess In Html Web Page

I am trying to remove the # in the following URL: (www.example.com/#section1). How could I do this using the htaccess file. I am sure this could be done using regular expression, b

Solution 1:

Hashes (#) are not send to the server, so you can't manipulate them on the server.

If you really need to remove them, you would have to use JavaScript on each page.

// Wait for the page to load, and call 'removeHash'.document.addEventListener("DOMContentLoaded", removeHash);
document.addEventListener("Load", removeHash);

functionremoveHash() {
    // If there is no hash, don't do anything.if (!location.hash) return;

    // http://<domain></pathname>?<search><#hash>// Build an URL for the page, sans the domain and hashvar url = location.pathname;
    if (location.search) {
        // Include the query string, if any
        url += '?' + location.search;
    }

    // Replace the loaded url with the built url, without reloading the page.
    history.replaceState('', document.title, url);
}

Post a Comment for "Removing '#' From Url Using Htaccess In Html Web Page"