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