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

Duplicate Homepage in search results with different hash-bang URLs

· 52CE 我爱测

I just realized that my homepage is present in google with three different URLs. https://www.example.com https://www.example.com/#!/page/2/ https://www.example.com/#!sweat-shirts So I guess I need to create a 301 redirect. How do…

问题原文

原帖链接 · Fred Delaunay · CC BY-SA 4.0

I just realized that my homepage is present in google with three different URLs.

https://www.example.com
https://www.example.com/#!/page/2/
https://www.example.com/#!sweat-shirts

So I guess I need to create a 301 redirect. How do I do that in WordPress?

社区高分解答

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

How has Google discovered these URLs? If you are linking to these URLs internally then this is something you need to fix.

It's not possible to 301 redirect these URLs because the fragment identifier (fragid) - everything after the # (hash), including the # itself, is not sent to the server as part of the HTTP request. You can only issue a 301 redirect from the server.

The fragid is only accessible from your client-side JavaScript (the original purpose of hash-bang #! URLs). You could potentially detect these fragid(s) in JS and issue a JS "redirect" - but this is just another 200 OK request, not a 3xx HTTP redirect. There may not be much point in doing this, since it's a low signal to search engines and potentially just slows your users. (Users are presumably seeing the same page regardless of whether the fragid is present or not?)

You should, however, set a rel="canonical" link element in the head section of your home page with the correct canonical URL. For example:

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

This informs search engines of the canonical URL for the page/URL currently being requested.

Note, there should always be a slash after the hostname, eg. https://www.example.com/. If this is omitted (in the search results) then it's just aesthetics.

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

资料来源与适用范围

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

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

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