Magento 2 Storeview in a subdirectory

You could run a storviewe in a subdirectory and it depends on your server (NGINX or apache) how you can configure this.

Follow the following instructions:

Disable Store Code in URL

This Configuration setting has to be disabled to be able to use subdirectories.

Stores > Settings > Configuration > General > Web > Url Options > Add Store Code to URLS

Configure Base URL

Foreach Base URL you have to add the subfolder at the end

For example


Dutch storeview:

French storeview:

Create Subfolders

Create a Subfolder for each different storeview, for which you configured the new base url, in the pub folder. This is because all request for each storeview will go through this folder.


mkdir ~/[pathToMagentoRoot]/pub/nl

mkdir ~/[pathToMagentoRoot]/pub/fr
Create Symlinks in the subfolder to the media, static, opt and errors folders. This is necessary to correctly load the media and theme files.

For example:

cd ~/[pathToMagentoRoot]/pub/fr ln -s ../media media

ln -s ../static static

ln -s ../opt opt

ln -s ../errors errors

Copy the index.php and .htaccess

Now you only have to copy the index.php and .htaccess from the pub folder and edit these according to the entry points.

For example:

In the index.php change the following sentence:

require realpath(DIR) . ‘/../app/bootstrap.php’;

require realpath(DIR) . ‘/../../app/bootstrap.php’;
Then edit .htaccess (only when you are running on an apache server). In this example there is only an explanation for nginx.

Nginx rewrite for each Storeview

Add the following block to your nginx configuration for each storeview:

location /[storeviewfolder]/ {

index index.php index.html index.htm;

try_files $uri $uri/