如何使用Javascript隐藏URL中的.html扩展 [英] How to hide .html extension in url using Javascript

查看:86
本文介绍了如何使用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

这篇关于如何使用Javascript隐藏URL中的.html扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆