How do I add NOINDEX, FOLLOW robots META tag to a custom 404 CMS page in Magento using XML, no matter what URL the page is served at?

By following the answer on this page, I was able to figure out how to target a specific Magento CMS Page (using the URL key) and then use a Layout Handle to change the robots META tag to NOINDEX, FOLLOW. Which would work great for a static page.

But my page is meant for 404 errors and is served at many different URLs. The problem with the solution in the link above is that it only works if the URL matches the URL key of the page. (The URL key of my 404 page is no-route-2) So if my 404 page is served at a URL that does not match the URL key ie. https://example.com/nothinghere, the robots META tag will not be updated.

But if you go to https://example.com/no-route-2 it will work.

I need the robots META tag of my page to have NOINDEX, FOLLOW no matter what URL it is served at.


It looks like this was a bug in Magento. You should be able to update HEAD tags or specifically the robots META tags using XML in the Layout Update XML field.

Here is a link to the issue on Github with the solution. https://github.com/magento/magento2/issues/4454

After vendor/magento/framework/View/Layout/etc/page_layout.xsd has been fixed you should be able to use

    <meta name="robots" content="NOINDEX,NOFOLLOW"/>


    <meta name="robots" content="NOINDEX,FOLLOW"/>

in the Layout Update XML field of the page in order to update the robots META tag.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.