There is a website that has multiple subcatogories which are stores in magento:

www.website.com/sub1 www.website.com/sub2 www.website.com/sub3

The server used is ngnix. everything is set up. And used to work, the nginx conf file for this site need to be reconstructed.

at the moment when for example www.website.com/sub1 is requested this wil set the store to store to sub1. which works fine. However when a product is asked i.e. www.website.com/sub1/product this returned a "page not found" error.

If the store is set to sub1 the url www.website.com/product DOES FIND the product without any issues. on the other hand f the store was not set previously, www.website.com/product DID NOT FIND the product.

it seemed that once a store is set the following happens e.g. www.website.com/sub1/product :

sub1->sub1->product == error (because of sub1->sub1)

this should be:


note that setting the store when www.website.com/sub1/product is requested and then redirecting the site to www.website.com/product is not an option. everything used to work fine! The store setup had not been changed. only the the nginx conf file should be adjusted. any sugestions?

server {

        listen 80 default;
        server_name website.com;
        root /www_folder;
        client_max_body_size 10M;

location / {
                index index.php;
                try_files $uri $uri/ @handler;
                expires 30d;

location /mage/ {
                try_files $uri $uri/ @magehandler;
                expires 30d;

    location @handler {
        ## Remove trailing slash
       rewrite ^/(.*)/$ /$1 permanent;
        ## Magento uses a common front handler
        rewrite / /index.php;

    location @magehandler {
        ## Adds a trailing slash to any urls that is missing a trailing slash
        rewrite ^(.*[^/])$ $1/ permanent;
        ## Magento uses a common front handler
       rewrite /mage/ /mage/index.php;

    ## These locations would be hidden by .htaccess normally, protected
    location ~ (/mage/(app/|includes/|lib/|pkginfo/|var/|errors/local.xml|shell/|tmp/|cron.+)|/\.git/|/\.ht.+)
        {deny all;}

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;

location  /. { ## Disable .htaccess and other hidden files
                return 404;

    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;

    location ~ \.php$ {
        add_header X-UA-Compatible 'IE=Edge,chrome=1';
        try_files $uri =404;
        expires off;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SERVER_PORT 80;
        fastcgi_param HTTPS $fastcgi_https;
| improve this question | | | | |
  • Does it work when you add index.php into the url? – brentwpeterson Jul 13 '15 at 15:44
  • nope tried it before... – john Jul 13 '15 at 15:58
  • Post your nginx configuration file. – brentwpeterson Jul 13 '15 at 16:35
  • posted! additional info: in the root folder there is an index.php file were magento is set to run the website via mage run code. In the root folder there are subfolders: one for each store. These folders each contain an index.php file were the store is set( again via mage run code) (the stores are being set correctly in these files). – john Jul 13 '15 at 17:33
  • sorry i tried www.website.com/sub1/index.php/product it does work. The thing is in some cases the redirection gives an infinite loop. anyway of fixing this without a redirection from store/.* to store/index.php/.*?? – john Jul 14 '15 at 9:02