request.path doubles the url.. Help!

Solved

request.path doubles the url.. Help!

DutchDelight
Excursionist
41 0 8

I have product pages that use a modified template. Template has had slight modifications, nothing big, really.

However, it has code that's coming from a structured-data.liquid file that was NOT modified.

 

The output on the website would for example be:

 

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Product",
"offers": [{
"@type": "Offer",
"name": "Default Title",
"availability":"https://schema.org/InStock",
"price": "12.34",
"priceCurrency": "USD",
"priceValidUntil": "2025-02-01","sku": "PRODX","url": "/products/item1/products/item1?variant=12345"

 

I've looked up where it would come from and it comes from that file. However, the url in question is just (outside of the variant) {{request.path}}

 

As you can see in the example above, it DOUBLES the path.. it should've been "/products/item1" and not "/products/item1/products/item1". Why is it doing this? Is there a way to prevent this from happening?

(most people won't notice it.. but Google picks up this path and then throws an error that it cannot be found..)

Accepted Solution (1)
Olllie
Shopify Partner
121 11 23

This is an accepted solution.

For my app autoSchema, which handles all this sort of thing automatically - I run my product URLs like this:
for products with variants: "url": "
{{ shop.url }}{{ product.url }}?variant={{ variant.id }}",
for products without variants: "url": "{{ shop.url }}{{ product.url }}"


Ollie | Founder & Developer of autoBlogger and autoSchema

autoBlogger: Seamlessly scheduled, fully automated, AI-powered, and SEO-optimised blogging with FAQs, table of contents and other features! Start your 14-day free trial today!


autoSchema: Fully automated and continuously updated Google structured data, including duplicate data removal. Simple to install – try it now!


Discover more at autoBlogger.bot!

View solution in original post

Replies 5 (5)

Olllie
Shopify Partner
121 11 23

Hey

 

Do you mind sharing the structured-data.liquid code that is being used to generate this script. I can take a look.

Ollie | Founder & Developer of autoBlogger and autoSchema

autoBlogger: Seamlessly scheduled, fully automated, AI-powered, and SEO-optimised blogging with FAQs, table of contents and other features! Start your 14-day free trial today!


autoSchema: Fully automated and continuously updated Google structured data, including duplicate data removal. Simple to install – try it now!


Discover more at autoBlogger.bot!

DutchDelight
Excursionist
41 0 8

Sure. Thing is.. that file came with the theme (Envy) and the file is structured-data.liquid. Not modified...

Part of the code in there is:

 

{%- capture main_entity_microdata -%}
"@type": "Product",
"offers": [
{%- for variant in product.variants -%}
{
"@type": "Offer",
"name": {{ variant.title | json }},
"availability": {%- if variant.available -%}"https://schema.org/InStock"{%- else -%}"https://schema.org/OutOfStock"{%- endif -%},
"price": {{ variant.price | money_without_currency | json }},
"priceCurrency": {{ shop.currency | json }},
"priceValidUntil": "{{ 'now' | date: '%s' | plus: days_product_price_valid_until | date: '%Y-%m-%d'}}",
{%- if variant.sku != blank -%}
"sku": {{ variant.sku | json }},
{%- endif -%}
"url": "{{ request.path }}{{ variant.url }}"
}{% unless forloop.last %},{% endunless %}
{%- endfor -%}
],
{%- if is_barcode_available and is_valid_gtin_length %}
"{{gtin_option}}": {{ product.selected_or_first_available_variant.barcode | json }},
"productId": {{ product.selected_or_first_available_variant.barcode | json }},
{%- elsif is_barcode_available %}
"mpn": {{ product.selected_or_first_available_variant.barcode | json }},
"productId": {{ product.selected_or_first_available_variant.barcode | json }},
{% else %}
"productId": {{ product.id | json }},
{%- endif %}
{%- if has_reviews -%}
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "{{ rating_value }}",
"reviewCount": "{{ review_count }}"
},
{%- endif %}
"brand": {
"name": "{{ product.vendor }}"
},
"name": {{ product.title | json }},
"description": {{ product.description | strip_html | json }},
"category": {{ product.type | json }},
"url": "{{ request.path }}{{ product.url }}",
"sku": {{ product.selected_or_first_available_variant.sku | json }},
"image": {
"@type": "ImageObject",
"url": "https:{{ product.featured_image | img_url: '1024x' }}",
"image": "https:{{ product.featured_image | img_url: '1024x' }}",
"name": {{ product.featured_image.alt | json }},
"width": "1024",
"height": "1024"
}

 

You'll fine request.path in there twice. Interestingly variant.url in the first instance and product.url in the second instance ALREADY contain the path, so those double whatever should've been there. I've just removed the request.path in both instances and tested it. I'm going with that for now.

Olllie
Shopify Partner
121 11 23

This is an accepted solution.

For my app autoSchema, which handles all this sort of thing automatically - I run my product URLs like this:
for products with variants: "url": "
{{ shop.url }}{{ product.url }}?variant={{ variant.id }}",
for products without variants: "url": "{{ shop.url }}{{ product.url }}"


Ollie | Founder & Developer of autoBlogger and autoSchema

autoBlogger: Seamlessly scheduled, fully automated, AI-powered, and SEO-optimised blogging with FAQs, table of contents and other features! Start your 14-day free trial today!


autoSchema: Fully automated and continuously updated Google structured data, including duplicate data removal. Simple to install – try it now!


Discover more at autoBlogger.bot!

DutchDelight
Excursionist
41 0 8

Aha.. yes, thank you for that hint. I replaced {{ request.path }} with {{ shop.url }}. It now looks good.

Olllie
Shopify Partner
121 11 23

No problem at all! Remember to mark as solved, if we have got this one sorted 🙂 

Ollie | Founder & Developer of autoBlogger and autoSchema

autoBlogger: Seamlessly scheduled, fully automated, AI-powered, and SEO-optimised blogging with FAQs, table of contents and other features! Start your 14-day free trial today!


autoSchema: Fully automated and continuously updated Google structured data, including duplicate data removal. Simple to install – try it now!


Discover more at autoBlogger.bot!