网站首页 > 技术文章 正文
为什么要去除首页文件 index.html?
1、保持简洁优雅的 URL。
保持网站首页简洁的域名格式。
2、搜索引擎友好,避免重复页面。
虽然大部分网站首页都是 index.html,但搜索引擎并不会将www.fuyeor.com/和www.fuyeor.com/index.html视为同一个页面,而是当作两个网址处理。
开始设置
1、设置网站目录文件默认值
从 Apache 服务器的配置文件 /conf/httpd.conf 中的 DirectoryIndex 修改网站默认首页。
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
确保www.fuyeor.com/和www.fuyeor.com/index.html都能正常访问。
2、在首页文件 index.html 中设置跳转
在首页文件 index.html 中通过 JavaScript 设置跳转,跳转至不带 index.html 的域名。
<script>
if(window.location.href == 'https://www.fuyeor.com/index.html'){
window.location.href="https://www.fuyeor.com/";
}
</script>
3、设置 rel=canonical <link> 标记,避免在搜索引擎出现 index.html
将具有 rel="canonical" 属性的 <link> 元素添加到带 index.html 的网页 <head> 部分中,并使其指向规范网页(主域名)。
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, viewport-fit=cover">
...
<link rel="canonical" href="https://www.fuyeor.com" />
...
</head>
这样搜索引擎即使发现了 index.html 的网址,也不会收录。
猜你喜欢
- 2024-10-21 HTML制作网页先熟悉CSS(用html和css做网页教程)
- 2024-10-21 HTML简单介绍及常见元素(html的元素组成部分有哪些?)
- 2024-10-21 Go Web 框架 Gin 学习2 - 模板渲染的2种方式
- 2024-10-21 HTML自定义组件(html 组件)
- 2024-10-21 Html小知识总结(html基础总结)
- 2024-10-21 你的HTML页面书写规范吗?必须知道的HTML书写规范
- 2024-10-21 用C++写出HTML,使用web服务,可以免费搭建个人博客
- 2024-10-21 【JavaScript】将执行上下文、作用域、闭包串联起来
- 2024-10-21 7.HTML中的列表、引用和代码的使用
- 2024-10-21 小白必看!Django 模板语言基础来啦
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)