user6813858 user6813858 - 1 month ago 17
Javascript Question

Modify url path without redirection

How i can modify url path like

example.com/blog_id=4&comment_id=5

to just
example.com
without redirection.
so the content gonna be of that long url but after
loading page it modifies it to that short url.

Answer

Your questions seems like .htaccess good usage:

RewriteEngine On 
RewriteRule ^/blog_id=\d+&comment_id=\d+$ example.com [NC,L]

You can also use JS window.history for that:

var stateObj = {blog_id: 4, comment_id: 5};
history.pushState(stateObj, "", "example.com");
history.replaceState(stateObj, "", "example.com");

Difference: when pushState and clicking back button you will be redirected to previous URL while replaceState will redirect to actual previous page that you visited before using replaceState

Comments