如何使用Javascript隐藏URL中的.html扩展

问题描述:

有什么方法可以使用JavaScript来隐藏来自URL的 .html 扩展名。

Is there any way to hide .html extension from URL using JavaScript.

例如:

mysite.html hide.html此处来自url

mysite.html hide.html here from url

您可以使用html5,但也可以在服务器端使用url重写或seo友好的url。

You can with html5, but also you can use url rewriting, or seo friendly urls, on the server side.

window.history.pushState({"html":'<html></html>',"pageTitle":'this is my title'},"", 'http://stackoverflow.com/mynewurl');

但请记住,您只能将网址更改为与原始网址相同的域!

However keep in mind you can only change the url to one which is the same domain as the original!

有一个很棒的图书馆叫做 history.js 有助于跨浏览器和版本兼容性

There is a great library called history.js which helps with cross browser and version compatibility