后台能搜索到商品,Status 也是 Enabled,但从前台地址访问却得到 404。商品是否可访问由多项条件共同决定,启用状态只是其中之一。

五项数据快速排除

  1. 商品是否分配到当前 Store 所属 Website;
  2. 目标 Store View 是否覆盖为 Disabled;
  3. Visibility 是否允许独立访问;
  4. request_path 是否存在且属于正确 store_id;
  5. 页面请求是否被自定义路由或旧 301 改写。
SELECT entity_id, sku FROM catalog_product_entity WHERE sku='ABC-001';
SELECT product_id, website_id FROM catalog_product_website WHERE product_id=123;
SELECT store_id, code, website_id FROM store ORDER BY store_id;

SELECT url_rewrite_id, request_path, target_path,
       redirect_type, store_id, is_autogenerated
FROM url_rewrite
WHERE entity_type='product' AND entity_id=123
ORDER BY store_id, redirect_type;

URL Rewrite 只存在 store_id=1,而请求进入 store_id=3,Magento 找不到对应路由。不要复制一条数据库记录伪造重写,应修正网站分配和 URL key 后让系统生成。

直接请求目标路径并保存跳转链

curl -skIL https://shop.example.com/red-shirt.html
curl -sk -o /tmp/product404.html -w '%{http_code} %{url_effective}
'  https://shop.example.com/red-shirt.html
grep -iE 'no-route|404|product' /tmp/product404.html | head

如果先 301 到错误 Store 再 404,检查 Base URL、Store Code 与历史重写;直接 404 则继续看产品初始化日志和重写表。

修复后同时验证商品原 URL、分类中的商品链接和 sitemap 中的 URL。旧地址如果已经被搜索引擎收录,应保留一次 301 到新地址,而不是把所有旧重写删除。

状态和可见性要读取目标 Store 的最终值

商品属性存在默认值和 Store View 覆盖。后台默认范围显示 Enabled,不代表当前 Store 也启用。使用产品 Repository 指定 store_id 读取最终状态、visibility 与 url_key,或查询对应 EAV store_id 记录。若切换 Store View 后发现 Use Default 未勾选,先确认这条覆盖是否业务需要,再决定删除或修改。

索引与缓存是最后一层

bin/magento indexer:status catalog_product_attribute catalogsearch_fulltext
bin/magento indexer:reindex catalog_product_attribute catalogsearch_fulltext
bin/magento cache:clean full_page block_html

重建后有结果说明更新链路存在积压,还要回查 Cron/MView;不能把每天 reindex 当成长期方案。