Using URL subfolders for multi-language Store Views in Magento 2
I configured Magento 2 with two Store Views in order to have two front-end languages (English and Italian) and I would like to have the following behaviour:
http://example.com/ --> Store View "English" (code = "en") - Default
http://example.com/it/ --> Store View "Italian" (code = "it")
That is, the English Store View should be available on standard urls and the Italian Store View should be available within the "it" subfolder in the url. Nothing strange, a common configuration for multilanguage websites.
I found here a quite similar question regarding Magento 1.x: Different storeviews or websites in subfolders. But since the accepted answer is not trivial (it involves rewrites in the .htaccess
and modifications in the index.php
), I would like to ask if with Magento 2 there is a simpler way to get this done?
UPDATE
Premise: I don't mind about having multiple websites so I don't have the problem to having several websites with the same languages (that would be a problem for the below solution).
So I enabled the Add Store Code to Urls
option, from Configuration > Web > Url > Add Store Code to Urls, and it's working good. But now I have duplicated urls for the default language (English):
http://example.com/ --> Store View "English" (code = "en")
http://example.com/en/ --> Store View "English" (code = "en")
http://example.com/it/ --> Store View "Italian" (code = "it")
Is there a way to avoid this, i.e. avoid the subfolder in the url for the default language?
magento2 store-view seo language ce
add a comment |
I configured Magento 2 with two Store Views in order to have two front-end languages (English and Italian) and I would like to have the following behaviour:
http://example.com/ --> Store View "English" (code = "en") - Default
http://example.com/it/ --> Store View "Italian" (code = "it")
That is, the English Store View should be available on standard urls and the Italian Store View should be available within the "it" subfolder in the url. Nothing strange, a common configuration for multilanguage websites.
I found here a quite similar question regarding Magento 1.x: Different storeviews or websites in subfolders. But since the accepted answer is not trivial (it involves rewrites in the .htaccess
and modifications in the index.php
), I would like to ask if with Magento 2 there is a simpler way to get this done?
UPDATE
Premise: I don't mind about having multiple websites so I don't have the problem to having several websites with the same languages (that would be a problem for the below solution).
So I enabled the Add Store Code to Urls
option, from Configuration > Web > Url > Add Store Code to Urls, and it's working good. But now I have duplicated urls for the default language (English):
http://example.com/ --> Store View "English" (code = "en")
http://example.com/en/ --> Store View "English" (code = "en")
http://example.com/it/ --> Store View "Italian" (code = "it")
Is there a way to avoid this, i.e. avoid the subfolder in the url for the default language?
magento2 store-view seo language ce
add a comment |
I configured Magento 2 with two Store Views in order to have two front-end languages (English and Italian) and I would like to have the following behaviour:
http://example.com/ --> Store View "English" (code = "en") - Default
http://example.com/it/ --> Store View "Italian" (code = "it")
That is, the English Store View should be available on standard urls and the Italian Store View should be available within the "it" subfolder in the url. Nothing strange, a common configuration for multilanguage websites.
I found here a quite similar question regarding Magento 1.x: Different storeviews or websites in subfolders. But since the accepted answer is not trivial (it involves rewrites in the .htaccess
and modifications in the index.php
), I would like to ask if with Magento 2 there is a simpler way to get this done?
UPDATE
Premise: I don't mind about having multiple websites so I don't have the problem to having several websites with the same languages (that would be a problem for the below solution).
So I enabled the Add Store Code to Urls
option, from Configuration > Web > Url > Add Store Code to Urls, and it's working good. But now I have duplicated urls for the default language (English):
http://example.com/ --> Store View "English" (code = "en")
http://example.com/en/ --> Store View "English" (code = "en")
http://example.com/it/ --> Store View "Italian" (code = "it")
Is there a way to avoid this, i.e. avoid the subfolder in the url for the default language?
magento2 store-view seo language ce
I configured Magento 2 with two Store Views in order to have two front-end languages (English and Italian) and I would like to have the following behaviour:
http://example.com/ --> Store View "English" (code = "en") - Default
http://example.com/it/ --> Store View "Italian" (code = "it")
That is, the English Store View should be available on standard urls and the Italian Store View should be available within the "it" subfolder in the url. Nothing strange, a common configuration for multilanguage websites.
I found here a quite similar question regarding Magento 1.x: Different storeviews or websites in subfolders. But since the accepted answer is not trivial (it involves rewrites in the .htaccess
and modifications in the index.php
), I would like to ask if with Magento 2 there is a simpler way to get this done?
UPDATE
Premise: I don't mind about having multiple websites so I don't have the problem to having several websites with the same languages (that would be a problem for the below solution).
So I enabled the Add Store Code to Urls
option, from Configuration > Web > Url > Add Store Code to Urls, and it's working good. But now I have duplicated urls for the default language (English):
http://example.com/ --> Store View "English" (code = "en")
http://example.com/en/ --> Store View "English" (code = "en")
http://example.com/it/ --> Store View "Italian" (code = "it")
Is there a way to avoid this, i.e. avoid the subfolder in the url for the default language?
magento2 store-view seo language ce
magento2 store-view seo language ce
edited Apr 13 '17 at 12:54
Community♦
1
1
asked Jul 31 '16 at 10:05
AndreaAndrea
1,09111026
1,09111026
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I ended up in using the below solution. I saw it is a quite common configuration for multi-language Magento websites.
This solution provides a default language with a redirect from "normal" url (urls without lang subfolder) to urls with the default lang subfolder.
For example, if it
is the default language, it happen this:
example.com/ --> example.com/it/
example.com/contact --> example.com/it/contact
...
1) Create store views with lang code
- Go to Stores > All Stores.
- Create a Store View for each language.
- Set in the Code field the language code.
- Example: I have two store views, Italiano with code "it" (default view) and English with code en.
2) Enable the Add Store Code to Urls option
- From Stores > Configurations > Web > Url Options > Add Store Code to Urls > Yes.
Enabling this option I have the following:
http://example.com/it/ --> Store View "Italian" (code = "it")
http://example.com/en/ --> Store View "English" (code = "en")
3) Set a default language redirect in the .htaccess
Open the .htaccess
and search for these lines:
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
Then place the following lines just before the above ones:
############################################
## redirects for urls without lang dir to default lang (it)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(it|en|adminw*|soap|rest)($|/.*$)
RewriteRule ^(.*)$ /it/$1 [L,R=301]
These lines will redirect all urls without language subfolder to the same url with default subfolder /it
at the beginning:
example.com/contact --> example.com/it/contact
Urls starting with en/
, admin
, soap/
, rest/
are not redirected.
You can customize it, changing the default language subfolder and adding other ignored urls (at least one for each language code you have).
4) Redirect the root to default language subdir
In the .htaccess
search for these lines:
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
Then place the following lines just after:
############################################
## redirect root to default lang (it)
RedirectMatch 301 ^/$ /it/
Drawbacks
I used this solution and it's working good for me. The only really drawback I have experienced is that the .htaccess
is rewritten each time I update Magento, so I have to restore it after the updating.
Another drawback can be if you have a multiple website configuration and several websites with the same languages as pointed out in a comment to this answer: https://magento.stackexchange.com/a/197/38275
add a comment |
Thanks for this solution, my only problem now is that I am losing access to all the css and js files under /skin/frontend.
Any tip?
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f128286%2fusing-url-subfolders-for-multi-language-store-views-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I ended up in using the below solution. I saw it is a quite common configuration for multi-language Magento websites.
This solution provides a default language with a redirect from "normal" url (urls without lang subfolder) to urls with the default lang subfolder.
For example, if it
is the default language, it happen this:
example.com/ --> example.com/it/
example.com/contact --> example.com/it/contact
...
1) Create store views with lang code
- Go to Stores > All Stores.
- Create a Store View for each language.
- Set in the Code field the language code.
- Example: I have two store views, Italiano with code "it" (default view) and English with code en.
2) Enable the Add Store Code to Urls option
- From Stores > Configurations > Web > Url Options > Add Store Code to Urls > Yes.
Enabling this option I have the following:
http://example.com/it/ --> Store View "Italian" (code = "it")
http://example.com/en/ --> Store View "English" (code = "en")
3) Set a default language redirect in the .htaccess
Open the .htaccess
and search for these lines:
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
Then place the following lines just before the above ones:
############################################
## redirects for urls without lang dir to default lang (it)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(it|en|adminw*|soap|rest)($|/.*$)
RewriteRule ^(.*)$ /it/$1 [L,R=301]
These lines will redirect all urls without language subfolder to the same url with default subfolder /it
at the beginning:
example.com/contact --> example.com/it/contact
Urls starting with en/
, admin
, soap/
, rest/
are not redirected.
You can customize it, changing the default language subfolder and adding other ignored urls (at least one for each language code you have).
4) Redirect the root to default language subdir
In the .htaccess
search for these lines:
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
Then place the following lines just after:
############################################
## redirect root to default lang (it)
RedirectMatch 301 ^/$ /it/
Drawbacks
I used this solution and it's working good for me. The only really drawback I have experienced is that the .htaccess
is rewritten each time I update Magento, so I have to restore it after the updating.
Another drawback can be if you have a multiple website configuration and several websites with the same languages as pointed out in a comment to this answer: https://magento.stackexchange.com/a/197/38275
add a comment |
I ended up in using the below solution. I saw it is a quite common configuration for multi-language Magento websites.
This solution provides a default language with a redirect from "normal" url (urls without lang subfolder) to urls with the default lang subfolder.
For example, if it
is the default language, it happen this:
example.com/ --> example.com/it/
example.com/contact --> example.com/it/contact
...
1) Create store views with lang code
- Go to Stores > All Stores.
- Create a Store View for each language.
- Set in the Code field the language code.
- Example: I have two store views, Italiano with code "it" (default view) and English with code en.
2) Enable the Add Store Code to Urls option
- From Stores > Configurations > Web > Url Options > Add Store Code to Urls > Yes.
Enabling this option I have the following:
http://example.com/it/ --> Store View "Italian" (code = "it")
http://example.com/en/ --> Store View "English" (code = "en")
3) Set a default language redirect in the .htaccess
Open the .htaccess
and search for these lines:
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
Then place the following lines just before the above ones:
############################################
## redirects for urls without lang dir to default lang (it)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(it|en|adminw*|soap|rest)($|/.*$)
RewriteRule ^(.*)$ /it/$1 [L,R=301]
These lines will redirect all urls without language subfolder to the same url with default subfolder /it
at the beginning:
example.com/contact --> example.com/it/contact
Urls starting with en/
, admin
, soap/
, rest/
are not redirected.
You can customize it, changing the default language subfolder and adding other ignored urls (at least one for each language code you have).
4) Redirect the root to default language subdir
In the .htaccess
search for these lines:
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
Then place the following lines just after:
############################################
## redirect root to default lang (it)
RedirectMatch 301 ^/$ /it/
Drawbacks
I used this solution and it's working good for me. The only really drawback I have experienced is that the .htaccess
is rewritten each time I update Magento, so I have to restore it after the updating.
Another drawback can be if you have a multiple website configuration and several websites with the same languages as pointed out in a comment to this answer: https://magento.stackexchange.com/a/197/38275
add a comment |
I ended up in using the below solution. I saw it is a quite common configuration for multi-language Magento websites.
This solution provides a default language with a redirect from "normal" url (urls without lang subfolder) to urls with the default lang subfolder.
For example, if it
is the default language, it happen this:
example.com/ --> example.com/it/
example.com/contact --> example.com/it/contact
...
1) Create store views with lang code
- Go to Stores > All Stores.
- Create a Store View for each language.
- Set in the Code field the language code.
- Example: I have two store views, Italiano with code "it" (default view) and English with code en.
2) Enable the Add Store Code to Urls option
- From Stores > Configurations > Web > Url Options > Add Store Code to Urls > Yes.
Enabling this option I have the following:
http://example.com/it/ --> Store View "Italian" (code = "it")
http://example.com/en/ --> Store View "English" (code = "en")
3) Set a default language redirect in the .htaccess
Open the .htaccess
and search for these lines:
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
Then place the following lines just before the above ones:
############################################
## redirects for urls without lang dir to default lang (it)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(it|en|adminw*|soap|rest)($|/.*$)
RewriteRule ^(.*)$ /it/$1 [L,R=301]
These lines will redirect all urls without language subfolder to the same url with default subfolder /it
at the beginning:
example.com/contact --> example.com/it/contact
Urls starting with en/
, admin
, soap/
, rest/
are not redirected.
You can customize it, changing the default language subfolder and adding other ignored urls (at least one for each language code you have).
4) Redirect the root to default language subdir
In the .htaccess
search for these lines:
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
Then place the following lines just after:
############################################
## redirect root to default lang (it)
RedirectMatch 301 ^/$ /it/
Drawbacks
I used this solution and it's working good for me. The only really drawback I have experienced is that the .htaccess
is rewritten each time I update Magento, so I have to restore it after the updating.
Another drawback can be if you have a multiple website configuration and several websites with the same languages as pointed out in a comment to this answer: https://magento.stackexchange.com/a/197/38275
I ended up in using the below solution. I saw it is a quite common configuration for multi-language Magento websites.
This solution provides a default language with a redirect from "normal" url (urls without lang subfolder) to urls with the default lang subfolder.
For example, if it
is the default language, it happen this:
example.com/ --> example.com/it/
example.com/contact --> example.com/it/contact
...
1) Create store views with lang code
- Go to Stores > All Stores.
- Create a Store View for each language.
- Set in the Code field the language code.
- Example: I have two store views, Italiano with code "it" (default view) and English with code en.
2) Enable the Add Store Code to Urls option
- From Stores > Configurations > Web > Url Options > Add Store Code to Urls > Yes.
Enabling this option I have the following:
http://example.com/it/ --> Store View "Italian" (code = "it")
http://example.com/en/ --> Store View "English" (code = "en")
3) Set a default language redirect in the .htaccess
Open the .htaccess
and search for these lines:
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
Then place the following lines just before the above ones:
############################################
## redirects for urls without lang dir to default lang (it)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/(it|en|adminw*|soap|rest)($|/.*$)
RewriteRule ^(.*)$ /it/$1 [L,R=301]
These lines will redirect all urls without language subfolder to the same url with default subfolder /it
at the beginning:
example.com/contact --> example.com/it/contact
Urls starting with en/
, admin
, soap/
, rest/
are not redirected.
You can customize it, changing the default language subfolder and adding other ignored urls (at least one for each language code you have).
4) Redirect the root to default language subdir
In the .htaccess
search for these lines:
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
Then place the following lines just after:
############################################
## redirect root to default lang (it)
RedirectMatch 301 ^/$ /it/
Drawbacks
I used this solution and it's working good for me. The only really drawback I have experienced is that the .htaccess
is rewritten each time I update Magento, so I have to restore it after the updating.
Another drawback can be if you have a multiple website configuration and several websites with the same languages as pointed out in a comment to this answer: https://magento.stackexchange.com/a/197/38275
edited Apr 13 '17 at 12:54
Community♦
1
1
answered Mar 1 '17 at 21:58
AndreaAndrea
1,09111026
1,09111026
add a comment |
add a comment |
Thanks for this solution, my only problem now is that I am losing access to all the css and js files under /skin/frontend.
Any tip?
New contributor
add a comment |
Thanks for this solution, my only problem now is that I am losing access to all the css and js files under /skin/frontend.
Any tip?
New contributor
add a comment |
Thanks for this solution, my only problem now is that I am losing access to all the css and js files under /skin/frontend.
Any tip?
New contributor
Thanks for this solution, my only problem now is that I am losing access to all the css and js files under /skin/frontend.
Any tip?
New contributor
New contributor
answered 4 mins ago
DesigniumDesignium
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f128286%2fusing-url-subfolders-for-multi-language-store-views-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown