大网数据广告活动
网站运营与故障问答

Duplicate title tags and meta descriptions after removing .html extension from files

· 52CE 我爱测

Google Webmaster Tools/Search Console is giving me errors regarding duplicate title tags and meta descriptions. The website in question is a static HTML website. All documents do have a .html extension. In order to remove the .ht…

问题原文

原帖链接 · Alex · CC BY-SA 3.0

Google Webmaster Tools/Search Console is giving me errors regarding duplicate title tags and meta descriptions.

The website in question is a static HTML website. All documents do have a .html extension. In order to remove the .html from all documents I am using the code below in my .htaccess file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

So for example http://example.com/about.html becomes http://example.com/about Now Google thinks that there are two separate about pages - even though it's only one. Can someone explain to me how to resolve this?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

If your .html URLs were already indexed at the time you changed your URLs (and removed the .html extension) then the only way to preserve your SEO and avoid duplicate content from the get go is to implement 301 redirects from the .html URL to your desired URL.

(This assumes you have changed all the URLs in your application to your desired "extensionless" URLs.)

Something like the following at the top of your .htaccess file:

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

The check against REDIRECT_STATUS is to avoid a redirect loop by ensuring the rewritten request (to .html) is not redirected (when the internal rewrite is triggered, REDIRECT_STATUS is set to 200).


In order to remove the .html from all documents I am using the code below in my .htaccess file

Aside: I guess this is probably just how you are describing it, but that isn't actually what that snippet of code does. You "remove the .html" from the URL by physically changing the URLs in your application (not with .htaccess). You then use .htaccess to internally rewrite the URL back to the actual filesystem path (with the .html extension) - and it's this that your snippet of code does. It re-appends the .html extension, it doesn't remove it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。