网站首页 > 知识剖析 正文
作者:玥言
链接:https://zhuanlan.zhihu.com/p/593377190
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
为什么要去除首页文件 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 的网址,也不会收录。
- 上一篇: 新区招聘骨干教师,最高70万科研安置费!
- 下一篇: 「来自提瓦特的祝福」网页活动现已开启
猜你喜欢
- 2025-01-29 贵州又一考试延期举行!退款流程及操作说明具体来看
- 2025-01-29 AI有多强大?这几个神奇的AI网站,可以直接改变你的生活质量。
- 2025-01-29 【CSS定位属性】用CSS定位属性精确控制你的网页布局!
- 2025-01-29 Nginx如何解决默认安装完后配置index.html访问一直不生效问题?
- 2025-01-29 「来自提瓦特的祝福」网页活动现已开启
- 2025-01-29 新区招聘骨干教师,最高70万科研安置费!
- 2025-01-29 “国六”来啦!7月1日起天津提前实施第六阶段国家轻型汽车大气污染物排放标准
- 2025-01-29 避免网站中出现 index.html(打开网页出现index)
- 04-29php开发者composer使用看这一篇就够了
- 04-29引用和变量声明在不同语言中的实作
- 04-29PHP 没你想的那么差
- 04-29Ubuntu linux 上的 Nginx 和 Php 安装
- 04-29CentOS下通过yum搭建lnmp(单版本PHP)
- 04-29为什么 PHP8 是个高性能版本
- 04-29PHP8函数包含文件-PHP8知识详解
- 04-29使用无参数函数进行命令执行
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)