PrestaShop .htaccess Redirects: Writing Rules Without Breaking Your Store
PrestaShop .htaccess Redirects: Writing Rules Without Breaking Your Store
The .htaccess file is one of the most powerful and dangerous files in your PrestaShop installation. A single misplaced character can take your entire store offline. But mastering .htaccess redirects is essential for SEO - you need them when changing URLs, migrating from another platform, removing old products, or restructuring your category tree. This guide teaches you how to write safe, effective redirect rules specifically for PrestaShop.
How PrestaShop Uses .htaccess
PrestaShop automatically generates and manages the .htaccess file. When you enable Friendly URLs in SEO & URLs settings, or click "Generate .htaccess file," PrestaShop writes rewrite rules between two marker comments:
# ~~start~~ Do not remove this comment, Prestashop will keep this comment block
# -- Your PrestaShop rules here --
# ~~end~~ Do not remove this comment, Prestashop will keep this comment blockCritical rule - Never add your custom redirects inside this block. PrestaShop will overwrite them the next time it regenerates the file. Place your custom rules BEFORE the PrestaShop block.
Understanding Redirect Types
301 - Permanent Redirect
Use when a page has permanently moved to a new URL. Search engines transfer the old page's SEO value (link juice) to the new URL. This is the most common redirect for e-commerce.
302 - Temporary Redirect
Use when a page is temporarily unavailable and will return to the original URL. Search engines keep the old URL indexed. Use this for seasonal pages, A/B tests, or maintenance.
410 - Gone
Use when a page has been permanently removed and there is no replacement. This tells search engines to remove the URL from their index. Useful for discontinued products with no alternative.
Basic Redirect Syntax
Simple One-to-One Redirects
# Redirect a single URL to a new location
Redirect 301 /old-page.html https://yourstore.com/new-page.html
# Redirect an old product URL
Redirect 301 /old-product-name.html https://yourstore.com/en/new-product-name.html
# Redirect an old category
Redirect 301 /old-category/ https://yourstore.com/en/new-category/Important - The first path (after 301) is relative to your domain root and must start with /. The second URL must be the full absolute URL including https://.
Pattern-Based Redirects with RewriteRule
For more complex redirects, use mod_rewrite with RewriteRule:
RewriteEngine On
# Redirect all pages from old domain structure
RewriteRule ^old-folder/(.*)$ https://yourstore.com/new-folder/$1 [R=301,L]
# Redirect product IDs to friendly URLs
RewriteRule ^product\.php\?id_product=([0-9]+)$ https://yourstore.com/en/product-$1.html [R=301,L]
# Redirect all .htm pages to .html
RewriteRule ^(.+)\.htm$ https://yourstore.com/$1.html [R=301,L]Common PrestaShop Redirect Scenarios
Scenario 1 - Migrating from Another Platform
When migrating from WooCommerce, Magento, or Shopify, your old URL structure will not match PrestaShop's. You need to redirect every old URL to its new PrestaShop equivalent.
# WooCommerce to PrestaShop - typical product URL migration
RewriteRule ^product/old-product-slug/?$ https://yourstore.com/en/new-prestashop-url.html [R=301,L]
# WooCommerce category to PrestaShop category
RewriteRule ^product-category/old-category/?$ https://yourstore.com/en/2-new-category.html [R=301,L]
# Magento to PrestaShop
RewriteRule ^catalog/product/view/id/([0-9]+)/?$ https://yourstore.com/en/product-$1.html [R=301,L]Scenario 2 - Removing a Language or Changing URL Structure
# Redirect old non-language URLs to new language-prefixed URLs
RewriteRule ^product-name\.html$ https://yourstore.com/en/product-name.html [R=301,L]
# Redirect old language prefix to new one
RewriteRule ^gb/(.*)$ https://yourstore.com/en/$1 [R=301,L]Scenario 3 - Forcing HTTPS and WWW
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force www
RewriteCond %{HTTP_HOST} ^yourstore\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourstore.com/$1 [R=301,L]
# Force non-www
RewriteCond %{HTTP_HOST} ^www\.yourstore\.com$ [NC]
RewriteRule ^(.*)$ https://yourstore.com/$1 [R=301,L]Scenario 4 - Removing Trailing Slashes
# Remove trailing slash (except for directories)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ https://yourstore.com/$1 [R=301,L]Scenario 5 - Bulk Product Redirects
When you have hundreds of old URLs to redirect, use a RewriteMap or include a separate file:
# Create a file called redirects.conf with your mappings
# Then include it (if your hosting allows)
# Or list them individually
Redirect 301 /old-product-1.html https://yourstore.com/en/new-product-1.html
Redirect 301 /old-product-2.html https://yourstore.com/en/new-product-2.html
Redirect 301 /old-product-3.html https://yourstore.com/en/new-product-3.htmlRules That Can Break PrestaShop
Infinite Redirect Loops
The most dangerous mistake. This happens when a rule redirects URL A to URL B, and another rule (or PrestaShop's own rules) redirects URL B back to URL A. The browser shows "Too many redirects" and the page never loads.
# DANGEROUS - can cause loops
RewriteRule ^(.*)$ https://yourstore.com/$1 [R=301,L]
# This redirects EVERYTHING, including the target URL itselfPrevention - always use conditions to prevent loops:
# SAFE - prevents loop by checking if already on correct host
RewriteCond %{HTTP_HOST} !^www\.yourstore\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourstore.com/$1 [R=301,L]Breaking API and Back Office Access
Overly broad redirect rules can break the PrestaShop back office, webservice API, and module controllers:
# DANGEROUS - redirects everything including admin URLs
RewriteRule ^(.*)$ https://yourstore.com/en/$1 [R=301,L]
# SAFE - exclude admin directory and API
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{REQUEST_URI} !^/api [NC]
RewriteCond %{REQUEST_URI} !^/modules [NC]
RewriteRule ^(.*)$ https://yourstore.com/en/$1 [R=301,L]Breaking Static Assets
Redirect rules that match CSS, JavaScript, and image files will break your store's appearance and functionality:
# DANGEROUS - redirects images and CSS
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
# SAFE - exclude static files
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|png|gif|svg|webp|woff|woff2|ttf|eot|ico)$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]Testing Your Redirects Safely
Step 1 - Always Back Up First
cp .htaccess .htaccess.backupStep 2 - Test with 302 First
Use temporary (302) redirects during testing. If something goes wrong, search engines have not cached the permanent redirect. Switch to 301 only after confirming everything works.
Step 3 - Test with curl
# Check redirect chain
curl -I -L https://yourstore.com/old-page.html
# Check specific redirect
curl -I https://yourstore.com/old-page.html
# Look for: HTTP/1.1 301 Moved Permanently
# And: Location: https://yourstore.com/en/new-page.htmlStep 4 - Verify in Google Search Console
After implementing redirects, use the URL Inspection tool in Google Search Console to verify that Google can follow the redirects correctly.
Where to Place Custom Rules
# YOUR CUSTOM REDIRECTS GO HERE (before PrestaShop block)
Redirect 301 /old-page.html https://yourstore.com/new-page.html
Redirect 301 /old-category/ https://yourstore.com/en/new-category/
# ~~start~~ Do not remove this comment, Prestashop will keep this comment block
# ... PrestaShop auto-generated rules ...
# ~~end~~ Do not remove this comment, Prestashop will keep this comment blockWhen to Use a Module Instead
Consider using a redirect module instead of manual .htaccess editing when:
- You have non-technical staff who need to manage redirects
- You need to manage hundreds of redirects with a UI
- You want automatic 404 detection and redirect suggestions
- You need redirect analytics (how many times each redirect is hit)
- You want to import/export redirects in bulk via CSV
Redirect modules store the mappings in the database and use a single PHP-based catch-all rule instead of adding lines to .htaccess. This is often safer and more maintainable for large redirect sets.
Quick Reference Cheat Sheet
| Task | Rule |
|---|---|
| Single page redirect | Redirect 301 /old https://site.com/new |
| Pattern redirect | RewriteRule ^old/(.*)$ https://site.com/new/$1 [R=301,L] |
| Force HTTPS | RewriteCond %{HTTPS} off + RewriteRule |
| Exclude directory | RewriteCond %{REQUEST_URI} !^/admin |
| Exclude file types | RewriteCond %{REQUEST_URI} !\.(css|js|jpg)$ |
| Remove trailing slash | RewriteCond %{REQUEST_FILENAME} !-d |
For more details, read our guides: PrestaShop .htaccess: Security and Performance Rules You Need and What Are Friendly URLs and Why Every PrestaShop Store Needs Them.
Was this answer helpful?
Still have questions?
Can't find what you're looking for? Send us your question and we'll get back to you quickly.