I have read loads of tutorials on how to set up a specific "store view" for the mobile version of my magento store.

My problem is that nobody really explain on how (after the different store views are being created) you can have magento show automatically one store view when browsing from mobile and another one when browsing on the desktop.

Where is the place where to insert the user agent expression?

Please note: I am not looking for how to change the theme, but instead how to show a different store view. What I need to do is being able to "switch on and off" different pages or static blocks when browsing the same theme from mobile or desktop.

maybe you can help me with this.

1 Answer 1


Magebase explains it quite well.

It is not changing the storeview, but changing the theme. You can add an exception, like:

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini

and then define a theme which is used instead, like iphone (included) or mobile (to implement by you)

To change the storeview, you have to change the MAGE_RUN_CODE in $_SERVER, this can be done on two ways:

  1. in VHost config / .htaccess via

    SetEnvIf Host www\.domain2\.com MAGE_RUN_CODE={storecode}

    so you can check the user agent (read the doc) and change the storeview based on this. Putting this in the VHost config is the best way (and removing the .htaccess)

  2. via index.php


$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? _SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? _SERVER['MAGE_RUN_TYPE'] : 'store';

Then another store view is loaded.

  • I have read that article, but that covers only on how to switch themes. What about store views? Is that impossible? I will want to use the same theme (i have a responsive theme), is the content (statick blocks) that I would like to be different. Thanks Jun 11, 2015 at 12:16
  • updated answer. Jun 11, 2015 at 12:23
  • This isn't recommended because you can't do things like alter the catalog, static blocks, etc.
    – philwinkle
    Sep 14, 2015 at 5:29
  • I read this and I don't get it. I'm also trying to load a different store view for mobile users (www.m.myDomain.com) but where do I define these exceptions you are talking about and what excatly do I put into the .htaccess file??
    – Allysin
    Dec 10, 2016 at 22:00
  • did you click the magebase link? @Allysin Dec 11, 2016 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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