Hi all.
I have a lot of rewrite rules (coming from Prestashop) that works as expected if the shop is located in the root path (ie: “/”).
These rules are stored in a snippet file so that I can include them in all domains by simply including a single config file.
Now, I have an issue: some prestashop installs are under a sub-folder (ie: ‘/shop’) and thus the rewrite regex doesn’t match anything, in example: rewrite ^/(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
I’ve thought to set a variable, called $shop_base_url and set to ‘/’ as default, overridden in each website config if the shop is in una subdirectory, but I can’t use the variable in the regex.
You should be able to use variables in the rewrite definition, you just have to make sure it is being set before the rewrite is hit. Do you have an example of the configurations that you have tried and did not work as expected?
We have multiple CMSs on this website, there is Laravel install on / and a prestashop install on /shop
Both have their own rewrite rules, so on Laravel, I have to “filter-out” anything related to prestashop. (how?)
Physical path for prestashop is different than the URL: shop is physically located in /public/shop but url is /shop so probably the try_files has to be changed in some way.
For filtering out the prestashop related assets, if there are references in the HTML that are trying to load assets that are not using the correct /shop path, you can use the sub_filter directive to rewrite those on the fly.
For the physical path part, does the config use proxy_pass to route the requests to the prestashop app? If it does, the path can be added on in that space. If it is a location on the filesystem, you can define a root directive in the location block to server data from a specific path on the system.
I’m not an nginx expert, i use it from less than a year.
This is my full virtualhost config (all virtualhosts are the same), could you please give me a working example?
So is the primary concern here that the rewrites are sent to /shop/img instead of /img? From looking at the prestashop docs you are missing a few location blocks to serve the files from. Does the default config work as expected, you just want to sometimes serve the static files from a different directory?
the rewrite config is much longer, i’ve posted just some test lines
standard config with PrestaShop in the root dir works, my issue is sharing the same config file (with some adjustments) allowing multiple PrestaShop installs in subdirs, in example:
Heya! Did you ever figure this out? You can’t really use variables as part of a regex in NGINX since the regex is compiled upon reloading NGINX (to optimize performance) whilst variables are only set when the respective variable setting directive is processed (e.g. set, map, or geo). You probably want to rethink the approach taken here, even though I don’t have any straight suggestions given my lack of familiarity with Prestashop.
I would also suggest asking in the Prestashop community too to see if anyone else is running a similar environment. There might be some Prestashop specifics that you need to take into account that we would not be familiar with here.