问题原文
原帖链接 · 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
.htmlfrom 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
