On first try of category pages I am only getting 404 errors.

I have Magento 2.1.5.

I imported about 20000 products in my single store, and the products are available in search.

But now I tried category tree from Codazon Megamenu. All links go to 404. This an example:

I tried several things:

  • magento indexer:reindex
  • magento setup:di:compile
  • cleared var/cache, var/generation, var/pagecache, var/di

Maybe its a problem that I have more than one root category?

Now I don't know what I can do to make it work. Google was my friend but I only found the methods described above.

What can I do?

  • Have you assigned the root category to your store? (stores -> All Stores -> current store)
    – Haritha
    Commented Jun 12, 2018 at 12:18
  • @tadeus Have you ever resolved this issue ?
    – anonymous
    Commented Mar 8, 2019 at 9:04

4 Answers 4


Delete all the Products and Category URLs from Database table "url_rewrite" and then trying to save the each category.

Also check for the URL suffix from configuration.

Store > Configuration > Catalog > Catalog > Search Engine Optimization

  • Catalog » Search Engine Optimisation » "URL Suffix" fixed for me 👍 👍
    – 00-BBB
    Commented Jan 7, 2020 at 9:28
  • This will destroy your SEO?
    – Black
    Commented Jun 20, 2022 at 9:17

If you are not an advanced user, use one root category. There may be may problems with URL rewrites for many root categories.
More info about it:
Magento 2.1.3 - Import products. Issue with categories

Are you able to go to any category page? Are you sure that Megamenu works fine? Maybe you have to update Megamenu settings e.g.URLs or positions?

  • >> if you are not advanced user, use one root category. <br /> ok, I try to move all with drag&drop to one category <br><br> >> Are you able to go to any category page? <br> no<br><br> >> Are you sure that Megamenu works fine?<br> I think so. The automatic build category tree gave me the URLs like in the first post. The IDs are true.
    – tadeus
    Commented Mar 29, 2017 at 12:53
  • Ok, try move all categories to one root category and we will check ;) Commented Mar 29, 2017 at 13:08

You can try this following ways

  • Open database and find core_config_data table. Run below Query into sql

    SELECT * FROMcore_config_dataWHERE path like '%web/seo/use_rewrites%'

Change the value of it 1 to 0.

Now Run the below code in cli

***rm -rf var/cache var/page_cache***
chmod 777 -R var/ pub/static generated/

I think, it will open inner page of your site. Next Step.......

To, remove index.php from URL ,

  • Need to enable mod_rewrite into Apache server.
  • web/seo/use_rewrites value will be 1.
  • Need to work on .htaccess file.

I wondered why it still showed 404, even after adding the URL suffix (see Rishabh Rk Rai's answer)

It was not working because the category was a subcategory of another. So I had to add the url part of the parent followed by the part of the subcategory obviously.

e.g. www.example.com/parentcat/subcat.html

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.