Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove or change .html extension in my url using javascript or jQuery? [duplicate]

My html page url is www.example.com/training/product.html. I want to change my url like to www.example.com/training/product. Is it possible using javascript or Jquery? How?

like image 617
sanman Avatar asked Sep 16 '25 08:09

sanman


2 Answers

Sorry I can not comment due to Reputation-Restriction.

The right solution is not yet in the comments.

window.history.replaceState()

does the job.

I would do:

var link = 'www.example.com/training/product.html';
link.split('.html')[0];
window.history.replaceState( null, null, link );

For a more respected solution go to How to reliably get the filename without the suffix in javascript?

Link:

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_replaceState().C2.A0method

like image 77
user32342534 Avatar answered Sep 17 '25 20:09

user32342534


You can do that by using MVC. This can not be done by Javascript. This needs to be done on server side.

like image 32
Chandan Avatar answered Sep 17 '25 22:09

Chandan