Magento 2 Get URL Without Trailing Slash in CMS Page and Block

The trailing slash at the end of the URL creates an issue of duplicate content on your website. URLs with and without trailing slash are considered as different pages by the Google search engine. Google considers these pages as two separate pages with the same content. In Magento 2 when you call any page in your CMS block using store URL it automatically adds a trailing slash at the end of URL. This blog post by Dhairvi Solutions helps you to know how to add a URL without trailing slash in the Magento 2

Understanding the Trailing Slash Problem

Search engine optimization (SEO) and website performance can be greatly impacted by seemingly insignificant issues in the field of web building. The trailing slash at the end of a URL is one example of such a feature. The fact that URLs with and without trailing slashes can result in duplicate content problems that lower search engine rankings is something that many website owners are ignorant of.

Magento’s Default URL Behavior

By default, when creating links in CMS pages and blocks, Magento 2 tends to automatically append a trailing slash to URLs. This may unintentionally result in the situation of duplicate content that we wish to prevent.

How to get URL without the slash in Magento 2

Thankfully, the direct_url feature in Magento 2 offers a straightforward way to eliminate the trailing slash. Using this technique, you may create slash-free, clean URLs right within your CMS text.

Here is a real-world example of using direct_url

<a href="{{store direct_url='about-us'}}">About Us</a>

You may improve SEO performance and avoid duplicate content problems by using Magento 2’s direct_url feature to build cleaner, more consistent URLs.

To learn how to re-run the existing patch in Magento 2, see our blog post “Magento 2 Execute Existing Data Patch”.

Privacy Policy © 2024-2026 Dhairvi Solutions LLP. All Rights Reserved.