Running Magento store view from a subdirectory

There are a couple of methods to achieve this, it just depends on which is more appropriate.

In our examples,

  • The domain is example.com
  • The store view URI is mynewstore
  • The store code is mynewstore_en
  • The run type is store

Method 1

If don't mind sharing the entire root directory with the other store (ie. if you don't have a unique blog etc.), then you can do the following.

Create a symlink from the desired URI to the main http dir

cd /microcloud/domains/example/domains/example.com/http`
ln -s mynewstore .`

Edit the ___general/example.com.conf file and add this

location ~* ^/mynewstore{
  location ~* .(php) {
    set $my_mage_run_code "mynewstore_en";
    set $my_mage_run_type "store";
    include fastcgi_params;
  }
  try_files $uri $uri/ /mynewstore/index.php$is_args$args;
}

Method 2

If you need to have unique folders within each installation, you should set up a symbolic link per directory that needs to be shared. Creating (and editing) a new index.php and symbolically links back to the respective directories as necessary.

Eg.

cd /microcloud/domains/example/domains/example.com/http
mkdir en
cd en
ls ../ | while read FILE; do
  ln -s ../$FILE .
done
rm index.php
cp ../index.php .

Then create the rewrite rule, edit the ___general/example.com.conf file and add this

location /en {try_files $uri $uri/ @en;}
location @en {
  rewrite . /en/index.php$is_args$args last;
}