5

I have an issue in a Magento 1.9.2.2 store that I can't quite figure out the solution for, so i was hoping for your assistance. There are 2 different store views each serving a different language. Those views are accessible by ULRs as the following:

base URL: www.example.nl

dutch version: www.exampe.nl/nl/cmspage

english version: www.example.nl/en/cmspage

The goal is to make the cms pages accessible only by using the correct country tag in the URL, this is working for the English part of the site but not for the Dutch.

To clarify:

www.exampe.nl/nl/cmspage is also accessible through www.exampe.nl/cmspage even when only nl is selected as storeview , the idea is to simply return a not found when trying to acces the cms page through www.example.nl/cmspage.

Any advice or tips you could give me on the subject would be greatly appreciated.

  • +1 as far as I know this is common behaviour for Magento. Maybee it should also be stated that a cms page is available with and without the language specifier (/nl in this case) only for the main storeview. All other storeviews don't have this issue/behaviour. I'm also looking for a solution. – Akif Apr 26 '17 at 15:07
  • Can you please add config URL settings (and maybe edits in index.php - magerun_type ...) Solution should be here at least tonight ... we'll need this in near future, too :) – sv3n May 17 '17 at 13:45
  • URL rewriting not working ? – Digital marketting May 22 '17 at 2:44
  • @Digitalmarketting do you mean "Use Web Server Rewrites = Yes"? This option is allready enabled. – Akif May 22 '17 at 9:11
  • @sv3n index.php and magerun_type are default. The config URL settings are also default. Only thing is we use SSL for both front and backend. So unsecure url is with https. – Akif May 22 '17 at 9:11
1
+50

Please try this. It redirects every cms page w/o storecode in URL to the same page with storecode.

app/code/local/My/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <version>0.0.1</version>
        </My_Module>
    </modules>
    <global>
        <models>
            <my_module>
                <class>My_Module_Model</class>
            </my_module>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch_cms_page_view>
                <observers>
                    <test>
                        <class>my_module/observer</class>
                        <method>test</method>
                    </test>
                </observers>
            </controller_action_predispatch_cms_page_view>
        </events>
    </frontend>
</config>

app/code/local/My/Module/Model/Observer.php

public function test(Varien_Event_Observer $observer)
{
    $controller = $observer->getEvent()->getControllerAction();
    $request    = $controller->getRequest();
    $storeCode  = $request->getStoreCodeFromPath();

    $p = explode('/', trim($request->getRequestUri(), '/'));
    if ($storeCode != $p[0]) {
        $controller->getResponse()->setRedirect($request->getBaseUrl() . '/' . $storeCode . $request->getPathInfo());
    }
}

Note: if i find a better solution, i'll update this post.

  • This is a good suggestion. I will try it out and report back. Is the code in the method tested? – Akif May 23 '17 at 11:18
  • Yes, it's tested and took me some time :P – sv3n May 23 '17 at 11:19
  • Works as expected +50. Also great to see it uses a 302 (moved) redirect. This is exactly what I was looking for. Thanks. Another thing; shouldn't this be in Magento core? At least as an option? – Akif May 23 '17 at 13:44
  • A guess it will not be part of Magento core ... but i'll open a PR (with config option) here github.com/OpenMage/magento-lts – sv3n May 23 '17 at 13:53
  • 1
    Opinion based ;) IMHO if i want to use storecodes in URL, they should alway be set. There are a lot of things that affect multistore users that should be fixed, e.g. storecode is unique so you can't set website1.com/en and website2.com/en, attribute settings are global, module config is global and many other things :( – sv3n May 23 '17 at 14:02
0

I think this question has very easy solution.

Follow solution.

goto your cms page from your admin panel open it in edit mode

in a very first tab you will find store setting.

so select those store only for that you want to access that page and disable , and make remain others as unselected

  • Thanks, but same here. Unfortunately this is not the solution. The page is allready assigned to dutch (nl) storeview only. But is still is also accessible without /nl. So both www.exampe.nl/nl/cmspage and www.exampe.nl/cmspage are accessible. – Akif May 22 '17 at 12:20
0

When creating cms page if you are selecting All Store Views the cms page will be available to all stores

so If you are using cms pages will be visible

www.exampe.nl/nl/cmspage
www.example.nl/en/cmspage

In case you do want the selected cms page in nl then you just need to select en store for the selected cms page you want.

In that case the selected cms page will be visible only to english store

www.example.nl/en/cmspage
  • Thanks, but this is not the solution. The page has allready been assigned to dutch (nl) storeview only.But is still is also accessible without /nl. So both www.exampe.nl/nl/cmspage and www.exampe.nl/cmspage are accessible. – Akif May 22 '17 at 12:19
  • Yes it may be available to both as both are redirected to same store I assume. So I am not able to understand are www.exampe.nl/nl/ and www.exampe.nl/ different stores ? – Priyank May 22 '17 at 12:24
  • www.exampe.nl/ is just the base url. There are only 2 storeviews /nl and /en. The Dutch (/nl) version is the "main" storeview. Every CMS pages becomes availalbe on www.exampe.nl/nl/cmspage and www.exampe.nl/cmspage. This causes duplicate content. When I select a storeview the cms page should only be available for that storeview, and not also from base url. Does this make the problem clear? – Akif May 22 '17 at 12:28
  • Since the base url is www.exampe.nl/ and your default store view is nl, so when you enter the base url without store code your default store view gets called which is nl so there is no duplication. – Priyank May 22 '17 at 12:31
  • I don't think I made it clear then. Because there is duplicate content. One single CMS page is available to view from both www.exampe.nl/cmspage and www.exampe.nl/nl/cmspage. This is what I don't want. Does this make the problem clear? – Akif May 22 '17 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.