1

The URLs of my website are www.example.com/?id=THEPRODUCTID#i where THEPRODUCTID is an alphanumeric string. Please note that #i is present at the end.

The problem is that Google crawlers are ignoring the #i specified on Sitemap.xml, so the results I can see on Google are www.example.com/?id=THEPRODUCTID.

As a quick solution, I want to create a servlet that redirects www.example.com/?id=THEPRODUCTID to www.example.com/?id=THEPRODUCTID#i. I am not sure how to do the mapping, or if it should be a filter, redirect, forward,... any guidance is very much appreciated.

2 Answers2

1

Everything that comes after # is called fragment and is intended to serve as a bookmark for a browser. The content that is served by the server for www.example.com/?id=THEPRODUCTID#i and www.example.com/?id=THEPRODUCTID will be absolutely the same.

If you build redirect functionality as you've suggested all requests to ww.example.com/?id=THEPRODUCTID will be redirected, not only the links generated by Google. If you're OK with that, use the following to redirect inside the servlet

response.sendRedirect("/id=THEPRODUCTID#i?);
Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • Thanks! I tried the below but Servlet is never called with `www.example.com/?id=asdfasdf`. Perhaps due to the regex? ` RedirectServlet com.a.m.server.RedirectServlet RedirectServlet /?id=([a-zA-Z]+) ` –  May 28 '14 at 22:58
  • 1
    serlet-mapping content is not exactly a traditional regexp. Take a look at this link to understand what's allowed: http://stackoverflow.com/questions/8570805/can-we-user-regular-expression-type-patterns-in-web-xml – Oleg Gryb May 29 '14 at 00:06
0

Look into url rewriting, for instance with Tuckey, and you can get rid of this whole procedure for your external urls, and keep it on the backend.

You can create rules to have your url be like www.example.com/product/THEPRODUCTID/i on the user end and get translated to www.example.com/?id=THEPRODUCTID#i in the backend.

developerwjk
  • 8,619
  • 2
  • 17
  • 33
  • Thanks! I am trying it but seems that it does not work properly, perhaps the '?' in the 'to'? ` /i/([a-zA-Z]+) /?id=$1#i ` –  May 28 '14 at 23:14
  • 1
    In the `to`, try with your servlet or JSP that responds as the welcomefile explicit: e.g. `/index.jsp?id=$1#i` – developerwjk May 28 '14 at 23:23