3

when we open a site : http://ab1.domain.com/

for first time in browser, it will redirect to below url

http://ab1.domain.com/://index.php/? & give 404 Not Found 1

://index.php/? is adding as suffix. but if we open 2nd time, than its working fine.

its multi-store site, when we disabled all stores also still problem is there.

Edit

It was problem with custom module , we are using this module for displaying respective currency based on country.

i dont want to disbale the custom module. I want solution with custom module enabled.

Observer.php

class Atwix_Ipstoreswitcher_Model_Observer
{
    /**
     * redirects customer to store view based on GeoIP
     * @param $event
     */
    public function controllerActionPostdispatch($event)
    {
        $cookie = Mage::getSingleton('core/cookie');
        if ($cookie->get('geoip_processed') != 1) {
            $geoIPCountry = Mage::getSingleton('geoip/country');
            $countryCode = $geoIPCountry->getCountry();
            if ($countryCode) {
                $storeName = Mage::helper('atwix_ipstoreswitcher')->getStoreByCountry($countryCode);
                if ($storeName) {
                    $store = Mage::getModel('core/store')->load($storeName, 'name');
                    if ($store->getName() != Mage::app()->getStore()->getName()) {
                        $event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));
                    }
                }
            }
            $cookie->set('geoip_processed', '1', time() + 86400, '/');
        }
    }
}

Data.php

class Atwix_Ipstoreswitcher_Helper_Data extends Mage_Core_Helper_Abstract
{
    const DEFAULT_STORE = 'India';

    /**
     * countries to store relation
     * default is English
     * @var array
     */
    protected $_countryToStore = array(
        'IN' => 'Indian Rupees [INR]',
        'US' => 'US dollar [$]',
        'FR' => 'Europe [€]',
        'AR' => 'US dollar [$]',
       // 'BO' => 'US dollar [$]'     

    );

    /**
     * get store view name by country
     * @param $country
     * @return bool
     */
    public function getStoreByCountry($country)
    {
        if (isset($this->_countryToStore[$country])) {
            return $this->_countryToStore[$country];
        }
        return self::DEFAULT_STORE;
    }
}

Edit 2

When i Go & System > Configuration > Web > Url options > Add Store Code to Urls : YES , If i set "YES" , than ://index.php/? will disappear. but Store codes are adding at the end of the url as like : http://ab1.domain.com/usa , http://ab1.domain.com/europe , but i want to keep only http://ab1.domain.com/

Edit 3

After following @Neklo.com answer , ://index.php/? is removed from url .

i changed to NO : System > Configuration > Web > Url options > Add Store Code to Urls : No

but now its adding ?___store=storecode at the end like ?___store=europe , ?___store=usa for 1st time , but 2nd time its working fine. so i followed link1 & link2 but store codes are still adding for the first time.

As i mentioned before, once i disable the module, it will work fine.

  • @RajeevKTomy thanks for your comment here. but i dont want to disbale the custom module. I want solution with custom module enabled. please help me for this. – Baby in Magento May 17 '16 at 6:10
  • I solved the same problem here: magento.stackexchange.com/questions/102068/… – Phoenix128_RiccardoT May 19 '16 at 7:22
  • @RiccardoT I read the post. Glad you helped op. can you help me what changes i need to do for this problem. we are using 1.9.2.0 – Baby in Magento May 19 '16 at 7:29
2
+50

If you redirected to "://index.php/" URL - that mean, store you trying to generate link to is not existing.

in other words: 'India', 'Indian Rupees [INR]', 'US dollar [$]', 'Europe [€]', 'US dollar [$]' - one of these store names is wrong for your system.

please check if "India" is correct store name ? as most likely you should locally get reidrect to default one from variants mentioned in "Atwix_Ipstoreswitcher_Helper_Data".

  • you are right, I wrote some wrong store name in Data.php. once i removed that, ://index.php/? is not adding in url. but now its adding ?___store=storecode like ?___store=europe , ?___store=usa . so i followed link1 & link2 but still its not working for me first time, but 2nd time its not adding like this. – Baby in Magento May 19 '16 at 6:25
  • ?___store=... - is correct magento functionality for redirect to store links – Neklo.com May 20 '16 at 16:53
  • But we don't want to display?___store=storecode in the url. – Baby in Magento May 23 '16 at 5:15
7

Best Solution

Contact developers of this extension and ask for solution in this particular case.

Some alternative solutions

I believe the problem happens in the following line from Observer.php

$event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));

Here particularly this code $store->getCurrentUrl(false) may be the origin of the problem. If you see, that line is trying to grab the current url without having any store url within it. With that, you can try following solutoins. It may work, but can't give 100% guarantee.

Solution 1

Replace $store->getCurrentUrl(false) with following code :

Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_forced_secure' => true));

This will also provide current url.

Solution 2

Use this:

 $currentUrl = Mage::app()->getRequest()->getBasePath().Mage::app()->getRequest()->getOriginalPathInfo();
 $event->getControllerAction()->getResponse()->setRedirect($currentUrl);
  • Now Url issue is fixed , but now module feature is not working. – Baby in Magento May 18 '16 at 7:16
2
class Atwix_Ipstoreswitcher_Model_Observer
{
    /**
     * redirects customer to store view based on GeoIP
     * @param $event
     */
    public function controllerActionPostdispatch($event)
    {

      if(!empty($_GET['___from_store']))
      {
          Mage::app()->setCurrentStore($_GET['___store']);
      }
      else
      {
         $geoIP = Mage::getSingleton('geoip/country');
        $cnCode =  $geoIP->getCountry();
       // echo $cnCode;
       // echo $cnCode='IN';
            switch ($cnCode) {
                case "US": {
                      Mage::app()->setCurrentStore('usa');
                      break;
                }
                case "IN": {
                    Mage::app()->setCurrentStore('india');
                    break;
                }
                case "CA": {
                    Mage::app()->setCurrentStore('northamerica');
                    break;
                }
                case "UK": {
                    Mage::app()->setCurrentStore('europe');
                    break;
                }

                case "AU": {
                    Mage::app()->setCurrentStore('australia');
                    break;
                }
          }              

        }

    }
}

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.