Showing results for 
Search instead for 
Did you mean: 

Duplicate content with store code in url

Duplicate content with store code in url


I have noticed an important issue and I'm surprised that nobody has given focus to it, so no solution found in internet yet.

I want to create a multilingual site (greek and english) and I have enabled "Add Store Code to Urls" and created two store views with the corresponding codes en (english) and el (greek).

I have set up greek as default.

The issue is that the system gives the exact same page if you go to and if you go to This of course is 100% duplicate content and will be for sure penalized!
So how can we solve this?
Possible solutions:
1. redirect all pages with /el/ to the one without it
2. redirect all pages without code to /el/ (my preference)
3. block access to pages without code

I'm using nginx.

How can achive the above? What implications we may have?
I would prefer to achieve solution 2. but if I do it with nginx redirects then if I hit /admin this will direct to /el/admin and this will create an infinite loop.
How all the people with multilingual sites solve this major issue? Am I missing something? I haven't found adequate solutions in internet

Here is also a similar question but they closed the subject without solution!


Re: Duplicate content with store code in url

E-commerce sites often utilize the manufacturer’s product description to detail the items they sell. The issue is that those items are often sold to multiple e-commerce sites. Then, the same description shows up on various sites and generates duplicate content. CredibleBH Employee Login

Re: Duplicate content with store code in url

Sorry but your answer is off topic.
The question is how to avoid having duplicate content between the following urls:

To avoid duplicate content one url should be redirected to the other. This should have be done from inside magento, but as magento has this bug at the moment we need to solve it with another way (eg. in nginx, apache etc)

Re: Duplicate content with store code in url

Hello @myrbourfak618d ,


I totally agree with your point that this should not be happening as it affects the SEO a lot and some integrations throws exception of duplicate pages.

I am sharing a solution below which will help you to redirect your off domains to default store with store code and if URL contains any store code, it will work without any bothering.


Create module with below files : 

1. registration.php



2. module.xml


<?xml version="1.0"?>
<config xmlns:xsi=""
    <module name="Vendor_Module" setup_version="1.0.0">

3. etc/frontend/events.xml



<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch">
        <observer name="force_storecode_redirect" instance="Vendor\Module\Observer\ForceStorecodeRedirectObserver" shared="false" />

4. Observer/ForceStorecodeRedirectObserver.php



namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class ForceStorecodeRedirectObserver implements ObserverInterface
    protected $storeManager;
    protected $url;
    /** @var array $storeCodes - array of existing storecodes*/
    protected $storeCodes = [];

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\UrlInterface $url
    ) {
        $this->storeManager = $storeManager;
        $this->url = $url;
        $this->storeCodes = array_keys($this->storeManager->getStores(false, true));

    public function execute(\Magento\Framework\Event\Observer $observer)
        $urlParts = parse_url($this->url->getCurrentUrl());
        $path = $urlParts['path'];

        // get storecode from URL
        $urlCode = trim(substr($path, 0, 4), '/');

        // If path does not already contain an existing storecode
        if (!in_array($urlCode, $this->storeCodes)) {
                header("HTTP/1.1 301 Moved Permanently");
                header("Location: " . $this->storeManager->getStore()->getBaseUrl() . substr($path, 1));



I hope it helps ! Smiley Happy



Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Duplicate content with store code in url

Hi @gaurav_harsh1 , your reply is the first I get that actually addresses the problem.

I see that you have been involved also in this thread
Do you have any idea why the thread is closed? Closing it was a mistake as the issue is still valid and important. Can we reopen it?

Anyway, I'll try your solution and I'll give some feedback. What I want to know is, your solution will be more resource and speed efficient if implented inside magento or an nginx redirect would be more resource and speed efficient and would leave magento intact?


Re: Duplicate content with store code in url

Hi @gaurav_harsh1,

i tested your solution and it works except from the home page. There I get the same content for and  so there is no redirect happening
It looks like you did it on purpose. Can you explain why? Then the home page will be considered duplicate.

I commented line 33 "if ($path != "" && $path != "/") {" to make home page redirect to the store code too, but I don't know the implications


Re: Duplicate content with store code in url

@myrbourfak618d ,


regarding nginx redirection :

Definitely the nginx would be faster because it would not reach to magento code and it would not process anything till then but in that case you have to manually put store codes and if you edit/add new store code you have to remember that and need to implement again. But with Magento’s customisation it would also not take huge time as it’s just comparing the store code but you don’t need to worry about store code modifications. So I would recommend the Magento redirection.


Home Page redirection :

Yes, remove 33 line condition as I copied from my earlier implementation where we had the country selector on home page and landing page was with store code. It will work perfectly after removing that.


PS : I have edited my solution and removed that condition.


Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Duplicate content with store code in url

Would be a SEO issue if my home page redirects to the store code url?

Re: Duplicate content with store code in url

No, there will not be any issue with SEO.

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Duplicate content with store code in url

Thanks for your help! I have one question:
Could it be possible that this Module doesn't work in Magento Version 2.4.5-p1?
I am new at Magento Developement and I installed the Module in a Version 2.3.6 Shop, there it works fine, but on a Version 2.4.5-p1 it doesn't work.