如何防止 google 网络爬虫将单个页面读取为两个不同的页面

How do I prevent google web crawler from reading a single page as two different pages

我有一个网页说 example.com/blog/news.php 我使用了这个代码:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php [NC,L]

.htaccess文件中隐藏文件扩展名。但是 google 爬虫读取 example.com/blog/news.phpexample.com/blog/news 作为两个不同的页面。请问我该如何防止这种情况,我试图将 news.php 页面重定向到 news 但它返回了一条错误消息,提示重定向过多或类似的东西。

您可以使用以下规则 301 将您的 .php URL 重定向到新的 (non-php ) 格式,这样 Google 只会索引您的新 URL.

将以下内容放在 RewriteEngine on 下方和现有规则之前:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([^.]+)\.php$ / [L,R=301]