Make site gwt crawlable without hash character?

In GWT, we need to use in the url to navigate from one page to another. To create a story, for example. but which is why I'm having a URL propagation issue. Google scrappers only read URLs up to ie . #

www.abc.com/#questions/10245857

#

www.abc.com

Now I want to remove #

from my url and want to save it as www.abc.com/question/10245857

.

I can not do it. How can i do this?

When the user browses the app, I use a hash url and a History object (as to avoid reloading pages). However, sometimes it is nice / necessary to have a cute URL (e.g. for sharing, showing publicly, etc.), so I would like to know how to specify the URL of the same page.

Note:
We need to do this to make our web pages url complete and link the site to the outside world.

+3


source to share


1 answer


There are 3 questions here and each can be resolved:

  • The url should look nicer to the user
  • Working with a direct url should work.
  • WebCrawlers must be able to receive content

These may all seem like the same problem, but in this context they are quite different.

Show multiple urls

Can be done with a small javascript file that uses HTML5 state methods . You can see a simple demo here , source here . This causes all changes to appear in "#" without "#" (in modern browsers).

Relevant code from the script:

var stateObj = {locationHash: hash};
history.replaceState(stateObj, "Page Title", baseURL + hash.substring(1));

      

Repsond to Pretty URLs

It's relatively easy if you have a listener in GWT to load based on "#" on page load. You can just throw away a simple re-direct servo that re-enters the "#" sign where it belongs when requests come in.



For a servlet listening on a pretty url:

if(request.getPathInfo()!=null && request.getPathInfo().length()>1){
    response.sendRedirect("#" + request.getPathInfo());
    return;
}

      

Alternatively, you can serve your GWT application directly from this servlet and initialize it with parameters from the url, but you need to be aware of the relative path to accounting.

WebCrawlers

This is the trickiest. Basically, there are no static (ish) pages here. It's not too difficult if there is a finite set of simple states that you index. One simple scheme is to have a separate servlet that returns the original content you would normally load with GWT in HTML format with minimal formatting. This servlet can have a different URL pattern such as "/ indexing /". They are not meant for humans, just web browsers. You can attach simple javascript in the <head> to redirect users to a nice url after the page has loaded.

Here's an example of a doGet method for such a servlet:

response.setContentType("text/html;charset=UTF-8");
response.setStatus(200);
pw = response.getWriter();
pw.println("<html>");
pw.println("<head><script>");
pw.println("window.location.href='http://www.example.com/#"
        + request.getPathInfo() + "';");
pw.println("</script></head>");
pw.println("<body>");
pw.println(getRawPageContent(request.getPathInfo()));
pw.println("</body>");
pw.println("</html>");
pw.flush();
pw.close();
return;

      

Then you should just have some links to those indexing pages hidden somewhere in the main app url (or behind a link in your main app url).

0


source







All Articles