1

I've upgraded to Magento 2.3.6 from 2.3.4 and am encountering this error anytime I try to update and save a CMS Page. It's limited just to CMS pages. Products and Categories are fine.

The error is: "The value specified in the URL Key field would generate a URL that already exists"

It doesn't matter what I update, it will still produce this error. The same when creating a new page.

I've tried truncating the url_rewrite table to no avail.

I can't see what is producing this error - there is simply not a Url Key in there that exists.

5 Answers 5

1

Got the same issue. In my case, the CMS page had a URL key identical to the 'frontName' specified in the modules routes.xml file.

So just change page Url key and then check it will work.

Quick fix is to disable this validator

vendor/magento/module-cms/Model/PageRepository.php b/vendor/magento/module-cms/Model/PageRepository.php 

Comment into below line.

//$this->validateRoutesDuplication($page);
0

The value specified in the URL Key field would generate a URL that already exists

its a generic error message which will be shown for the following reasons

  1. Duplicate product creation
  2. Duplicate category creation
  3. Duplicate url_key entries
  4. Duplicate cms page identifier

The latter one could be the cause in your case

Check the file below and debug the method execute()

vendor\magento\module-cms\Controller\Adminhtml\Page\Save.php

and also check this one below and debug beforeSave(), to get the exact cause of this issue

vendor\magento\module-cms\Model\Page.php

Also try to duplicate your CMS page and confirm whether you are able to save.

0

It may always be the case that the url you defined is already in use for another page.

There is one exception, I experienced it Updating from 2.3.x to 2.4.3-p1 and it looks like Magento has "reserved" specific URL such as "shipping","klarna","checkout","cart" see the following github ticket: https://github.com/magento/magento2/issues/35115

The quick fix for now is to deactivate the validation in /vendor/magento/module-cms/Model/PageRepository.php

and uncomment the line

$this->validateRoutesDuplication($page);

0

Attention: There are some reserved url keys from Magento side and also installed modules that you cannot use them as frontend url keys. You can find the list of them from vendor/magento/framework/App/Route/Config.php in getRouteByFrontName method from $this->_getRoutes($scope) when sending frontend as scope (just put this line in your debugger's watcher and there will be an array with the reserved url keys.)

After all and if you really need to bypass, I believe commenting $this->validateRoutesDuplication($page); is not a solution cause it might make duplicates in url keys but bypassing with a condition is a harmless solution. I'm going to add a condition that checks if we want to update or create a page and if it's an update,then bypass the validation but if we are creating a new page with the same identifier, then we need to prevent this. So this is what I added in vendor/magento/module-cms/Model/PageRepository.php in save method:

if ($page->getOrigData() === null) {
      $this->validateRoutesDuplication($page);
}

This condition will check if it's an update or a create and bypass if it's an update.

0

I was facing the same issue for a certain CMS page and I have solved it differently. The error message was The value specified in the url_key field would generate a URL that already exists when saving the CMS page from admin. In my case, it was a conflicting CMS page URL key with module routes frontName.

  1. The first developer creates a CMS page with the url_key careers.
  2. The second developer creates a frontend route with frontName careers in a custom module.
  3. Now when someone tries to save the CMS page with url_key careers, he is getting the error. but the other pages are saving well.
  4. New when I change the frontName from careers to career, the CMS page with url_key careers is saving well.

The etc/frontend/routes.xml file sample:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="career" frontName="career">
            <module name="Vendor_Module"/>
        </route>
    </router>
</config>

So in my case the issue was conflicting CMS page url_key with the custom module's frontend routes frontName.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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