You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrestaShop修改SEO规则后旧URL如何重定向至新URL?

Fixing PrestaShop 301 Redirects After Adding .html URL Suffixes

Got it, let's tackle this issue head-on. When you update your PrestaShop SEO settings to add .html suffixes to product/category URLs, broken old URLs and missing 301 redirects can tank your SEO and frustrate users. Here are the most reliable solutions to get those redirects working:

1. Enable PrestaShop's Built-in Canonical Redirects

First, check if you're leveraging PrestaShop's native URL handling. Head to your admin panel:

  • Go to SEO & URLs > Set up URLs
  • Look for the option Auto-redirect to the canonical URL and check the box
  • Save your changes

This setting tells PrestaShop to automatically redirect users to the official (canonical) version of a URL. While it might handle some cases, it often needs a boost for suffix changes like adding .html.

2. Bulk Redirects via .htaccess (Best for Large Stores)

For a universal fix that covers all old non-.html URLs, add custom rewrite rules to your root .htaccess file. This is the fastest way to handle hundreds or thousands of products/categories at once.

Open your .htaccess file (located in your PrestaShop root folder) and add these rules right after the RewriteBase / line:

# Redirect non-.html product URLs to .html version
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)-([a-zA-Z0-9-]+)$ $1-$2.html [L,R=301]

# Redirect non-.html category URLs to .html version
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)$ $1.html [L,R=301]

Notes:

  • Test this immediately by visiting an old non-.html URL (e.g., yourstore.com/123-product-name should redirect to yourstore.com/123-product-name.html)
  • If your store uses a custom URL structure (no product ID in URLs), adjust the product rewrite rule to match your setup
  • Always back up .htaccess before editing to avoid breaking your site

3. Manual Redirects for Edge Cases

If you have a handful of high-priority pages that aren't covered by the .htaccess rule, use PrestaShop's URL Redirect tool:

  • Go to SEO & URLs > URL Redirects
  • Click Add new redirect
  • Enter the old URL path (e.g., /old-category) in the Request URL field
  • Enter the new .html URL (e.g., /old-category.html) in the Target URL field
  • Set the Type to Permanent (301) and mark it as active
  • Save the redirect

4. Database-Level Batch Redirects (Advanced)

If you need granular control or have unique URL structures, you can directly populate PrestaShop's redirect table via SQL. Always back up your database first before running any queries.

Use this SQL query (replace ps_ with your database prefix if it's different) to create redirects for all products:

INSERT INTO ps_redirect (id_redirect, id_shop, id_lang, request_uri, redirect_uri, type, active)
SELECT NULL, 1, id_lang, CONCAT('/', link_rewrite), CONCAT('/', link_rewrite, '.html'), '301', 1
FROM ps_product_lang
WHERE link_rewrite IS NOT NULL;

For categories, use this query:

INSERT INTO ps_redirect (id_redirect, id_shop, id_lang, request_uri, redirect_uri, type, active)
SELECT NULL, 1, id_lang, CONCAT('/', link_rewrite), CONCAT('/', link_rewrite, '.html'), '301', 1
FROM ps_category_lang
WHERE link_rewrite IS NOT NULL;

Important:

  • Adjust id_shop to match your store ID (use 1 for single-store setups)
  • After running the query, clear PrestaShop's cache to apply the changes

内容的提问来源于stack exchange,提问作者user960971

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:56:12