Jump to content

PS in a subdirectory with nginx


ale123

Recommended Posts

Hi all.

I have a website with 3 different prestashop installs. Each install has to be in a subdirectory (except the first install), in example:

mydomain.tld/
mydomain.tld/shop2/
mydomain.tld/shop3/

Any idea how to create this with nginx ? In Apache there is a REWRITE_BASE parameter that should be enough, but what about nginx ? I did many test and i wasn't able to reach the goal.

Any tested and working config ?

Link to comment
Share on other sites

  • 2 weeks later...

As you said, you have installed 3 different PrestaShop then everything will work as per your installation.

If you have installed PrestaShop into the subdirectory (like ROOT_DIR/shop2), you can access it by default from the installed locations:

For shop 1: mydomain.tld
For shop 2: mydomain.tld/shop2/
For shop 3: mydomain.tld/shop3/

Link to comment
Share on other sites

standard rewrite rules for nginx doesnt work if PS is in a subdir because the makes use of '/' as leading path.

 

a workaround is to customize ALL rules for all installs replacing '/' with '/shop2/' and so on but im trying to find a better solution that doesnt need to change every line every time. maybe with an nginx variable or similiar

Link to comment
Share on other sites

Posted (edited)
On 4/22/2025 at 2:36 PM, ale123 said:

Any tested and working config ?

for what exactly?

What do you wish to accomplish.
Hopefully you are on a dedicated server. On a shared host you'd run out of RAM extraquick

Edited by Nickz (see edit history)
Link to comment
Share on other sites

Just now, Nickz said:

for what exactly?

What do you wish to accomplish.
Hopefully you are on a dedicated server. On a shared host you'd run out of RAM extraquick

It' wrote above: a working config for nginx with prestashop in a subdirectory and non in the root folder. The standard nginx config for prestashop works only if installed in the root, because all rewrite rules assumes that the shop is in "/" because all rewrite rules are using absolute paths. I would like to find a better way than manually editing every rewrite rule on each website based on the directory name. 

 

In apache there is a RewriteBase option that does this automatically, just set the RewriteBase on top of the .htaccess and you're done. All subsequent path (that has to be changed to be relative and not absolute) are prefixed with the RewriteBase value.

  • Like 1
Link to comment
Share on other sites

we have had new clients enter with non-reproducible issues, this is generally caused  by prestashop cache modules (avoid) and having nginx.  When we either remove ps cache module or change hosting to run apache problems disappear.  

 

Detriments or Considerations

PrestaShop Compatibility

  • PrestaShop is designed with Apache in mind, especially .htaccess rules for SEO URLs, caching, and overrides.
  • Nginx does not use .htaccess, so you must manually convert Apache rules to Nginx config, which can be tricky and error-prone.
  • Module & URL Handling
  • Some PrestaShop modules may assume Apache-specific behavior (mod_rewrite, mod_security).
  • URL rewriting and overrides can break if not configured correctly in nginx.conf.
  • Most PrestaShop community support and tutorials are written with Apache in mind.
  • You may run into less tested territory when debugging Nginx-specific issues.

Admin Panel Issues

If Nginx caching is too aggressive or misconfigured, it can cause BO (Back Office) issues such as stale pages or token errors.

so my advice from experience is to use apache

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...