3

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?

1 Answer 1

7

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.

1
  • My homepage is using the canonical link tag. But i don't know how Google found these pages. I used Xenu, it found nothing. May 22, 2022 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.