PrestaShop .htaccess Optimization Guide 2025 – Improve Speed and SEO

L'équipe PrestaInsights

Introduction

PrestaShop is a powerful open-source eCommerce platform. However, to truly unlock its performance potential, server-level configuration plays a vital role. One of the most impactful tools at your disposal is the .htaccess file — a configuration file used by Apache servers.

In this guide, you’ll learn how to optimize your .htaccess file specifically for a PrestaShop store. This includes implementing clean redirects, enabling compression and caching, securing sensitive files, and improving load times — all crucial for performance and SEO in 2025.

What Is the .htaccess File in PrestaShop?

The .htaccess file is a plain text file located in the root directory of your PrestaShop installation. It controls how Apache serves your site by configuring server directives on a per-directory basis.

When used correctly, .htaccess allows you to:

  • Enable friendly URLs

  • Redirect outdated or broken links

  • Improve caching behavior

  • Compress files to reduce load time

  • Restrict access to sensitive files

  • Improve security with headers and request filtering

PrestaShop generates a default .htaccess file automatically when you enable friendly URLs from the back office, but you can manually enhance it further for performance and control.

Why Optimize the .htaccess File?

Optimizing your .htaccess file benefits your PrestaShop store in multiple ways:

  • Faster Page Load: Through compression and browser caching

  • Better SEO: Canonical redirection and clean URLs

  • Enhanced Security: Block access to sensitive files and scripts

  • Improved Resource Efficiency: Minimize server load from bad bots and hotlinking

Let’s go through each optimization step-by-step.

Step-by-Step PrestaShop .htaccess Optimization

1. Enable Friendly URLs

Before making any manual changes, make sure that friendly URLs are enabled:

  • Go to your PrestaShop Back Office

  • Navigate to Shop Parameters > Traffic & SEO

  • Enable “Friendly URL”

This will generate a base .htaccess file automatically. You can now safely append optimization directives.

2. Redirect to Canonical URL

To prevent duplicate content and enforce consistent domain usage, choose either the www or non-www version and redirect accordingly.

# Redirect to www\RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
# Redirect to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]

3. Enable GZIP Compression

Reducing file size via compression helps reduce page load times significantly.

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/html text/css application/javascript application/json image/svg+xml
</IfModule>

Make sure mod_deflate is enabled on your server. You can confirm via your hosting provider or a tool like GTmetrix.

4. Leverage Browser Caching

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

5. Prevent Directory Browsing

Options -Indexes

6. Block Access to Sensitive Files

<FilesMatch "(\.htaccess|config\.inc\.php|db\.settings\.php)">
  Order allow,deny
  Deny from all
</FilesMatch>

7. Prevent Image Hotlinking

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://(www\.)?yourdomain\.com/ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [F,NC,L]

8. Enable Custom Error Pages

ErrorDocument 404 /error-pages/404.html
ErrorDocument 403 /error-pages/403.html

9. Set Strict Transport Security (HSTS)

<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</IfModule>

10. Deny Bad Bots

SetEnvIfNoCase User-Agent "MJ12bot" bad_bot
SetEnvIfNoCase User-Agent "AhrefsBot" bad_bot
SetEnvIfNoCase User-Agent "SemrushBot" bad_bot
Deny from env=bad_bot

PrestaShop Default Rewrite Rules Overview

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Testing Your Optimizations

After editing your .htaccess, use these tools to measure improvements:

  • Google PageSpeed Insights

  • GTmetrix

  • Pingdom Tools

  • WebPageTest

  • Lighthouse (Chrome DevTools)

Look for improved scores in metrics such as Time to First Byte (TTFB), fully loaded time, and number of requests.

Troubleshooting and Best Practices

  • Always back up your .htaccess file before making changes.

  • A single syntax error can break your website. Use syntax validators like htaccess.madewithlove.be.

  • Use # to comment out sections for testing.

  • If your hosting uses NGINX or LiteSpeed, .htaccess rules may not apply. Ask your host for the proper configuration file.

Conclusion

A well-optimized .htaccess file can significantly boost your PrestaShop store’s performance, security, and SEO. From enabling GZIP and caching to managing redirects and blocking harmful traffic, these adjustments give you more control over how your site behaves.

By following this guide, you’re not only making your store faster but also aligning with best practices expected in 2025 and beyond. As PrestaShop continues to evolve, optimizing server-level settings like .htaccess ensures your store remains fast, secure, and competitive.

Rédigé par

L'équipe PrestaInsights

Chez PrestaInsights, nous sommes spécialisés dans tout ce qui concerne PrestaShop, de l'hébergement et l'optimisation des performances au développement de modules et aux tutoriels approfondis. Notre objectif est d'aider les commerçants, les développeurs et les agences à réussir grâce à des guides à jour, des aperçus pratiques et des meilleures pratiques éprouvées. Que vous débutiez ou que vous développiez une boutique à fort trafic, nous sommes là pour vous guider.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont marqués d'une *