How to use RDFa with Google and HTML head <base> tag

367 Views Asked by At

On a website, we are using a HTML head base tag. The reason is the convenience of linking to static resources through relative URLs and it's very hard to change. Content URLs are always fully qualified. So the head section looks like:

<head>
    <base href="http://example.com/static/" />
</head>

Now, we are using RDFa to specify structured data on the page. To populate i.e. a schema:Product page, say http://example.com/product1. Now, the problem comes from the base tag: in the absence of any other reparation, the RDFa parser considers the whole RDFa data is about http://example.com/static, not about http://example.com/product1.

We have tried with mixed results adding the property about="http://example.com/product1" on either <html> or <body>.

This intermittently works with Google's Structured Data Testing Tool. Intermittently in the sense that about 2 months ago it seemed to work when added to <body>, now it appears to work when added to <head>.

However, in the Search Console under "Structured Data" the situation is not even intermittently working. It used to work about 8 months ago with <html about="..."> but now it just doesn't work either way. I mean the pages are indexed, but not the structured data.

So, is there a standard, tried and proven way to make Google (and any generic meta parser) properly know the URL of a webpage that has a generic <base href="" /> tag that is different to its actual URL?

Example 1

Assume the following is rendered by HTTP GET http://bar.com/product1

<html prefix="schema: http://schema.org/">  
    <head>  
        <base href="http://foo.com/" />  
    </head>  
    <body about="http://bar.com/product1" typeof="schema:Product">  
        <span property="schema:name">Bar product</span>  
    </body>  
</html>  

The above:

  • Was working with Google based on Google Search Console / Structured Data ~8 months ago and Google Structured Data Testing Tool ~2 months ago
  • Is not working with Google based on Google Search Console / Structured Data since 8m ago (no errors reported, but new content is not fetched into structured data report), is not parsing with Testing Tool ATM

Example 2

<html prefix="schema: http://schema.org/" about="http://bar.com/product1" typeof="schema:Product">
    <head>  
        <base href="http://foo.com/" />  
    </head>  
    <body>  
        <span property="schema:name">Bar product</span>  
    </body>  
</html>  
  • Was not parsing with Google Structured Data Testing Tool ~2 months ago
  • Is parsing with Google Structured Data Testing Tool ATM
  • Is not working with Google based on Google Search Console / Structured Data ATM (no errors reported, but new content is not fetched into structured data report)
1

There are 1 best solutions below

4
unor On

Both of your example snippets seem to work correctly in Google’s Structured Data Testing Tool. As one would expect, they generate the same output.

@type Product
@id http://bar.com/product1
name Bar product

I can’t test it in Google’s Search Console, but I could imagine that the issue you see is not related to the RDFa markup.

Anyway, you could try to use resource instead of about. While both ways are fine in RDFa, RDFa Lite supports only resource. I’m not saying that Google only supports RDFa Lite (probably not, because their SDTT seems to support about fine), but when they refer to RDFa, they typically link to the RDFa Lite spec.

<html prefix="schema: http://schema.org/">  
    <head>  
        <base href="http://foo.com/" />  
    </head>  
    <body resource="http://bar.com/product1" typeof="schema:Product">  
        <span property="schema:name">Bar product</span>  
    </body>  
</html>