301将index.html重定向到index.php并从url隐藏index.php

时间:2016-08-19 13:20:47

标签: url-redirection

我最近将网站页面更改为.php 之前我有一个重写规则,将example.com/index.html显示为example.com /

现在我想要相同但重定向到index.php

我尝试了一些但是我以循环结束了.. 这样做的正确方法是什么? 这一切都是为了防止谷歌将index.php作为新页面而不是index.html的演变 我想用htaccess完成所有这些,我已经通过这种方式为每个其他页面做了这个:

重定向301 /old-url-name.html http://www.example.com/new-url-name.php

另外..有一种方法可以隐藏所有index.php来自各自的文件夹吗?

1 个答案:

答案 0 :(得分:0)

要阻止Google为两个网址编制索引,您必须使用canonical元标记:

<link rel="canonical" href="https://www.example.com/" />

不需要从index.php重定向,只是不要将index.php页面链接到站点中的任何位置。换句话说,替换它:

<a href="https://www.example.com/index.php">Home</a>

用这个:

<a href="https://www.example.com/">Home</a>
相关问题