Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7892823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:57:51+00:00 2026-06-03T06:57:51+00:00

i have option Store Code to Urls turned on (admin -> system -> configuration

  • 0

i have option “Store Code to Urls” turned on (admin -> system -> configuration -> web -> url options).

Problem is that if i access my homepage without store code, it works. I mean both examples works:
http://example.com/
http://example.com/code/
But first url (without store code) should redirect to url with store code. I’ve tried to put rewrite rules in htaccess but without success, i’ve tried planty of possibilities.

Magento build in rewrites rules doesnt seem to be helpfull – i’ve tried rewrite “/” to “code”, but it result with “/code/code” url suffix.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:57:52+00:00Added an answer on June 3, 2026 at 6:57 am

    The reason for this behavior can be found in Mage_Core_Model_Url_Rewrite::rewrite. There is no redirect for base URLs without store code.

    Below is a pretty ugly solution, but it should work in your case. It will redirect to the base URL including store code as long as current store code is not found in the request URI:

    app/code/local/Danslo/RedirectToStore/Model/Observer.php:

    <?php
    
    class Danslo_RedirectToStore_Model_Observer
    {
    
        public function redirectToStore($observer)
        {
            $request    = $observer->getFront()->getRequest();
            $storeCode  = Mage::app()->getStore()->getCode();
            $requestUri = $request->getRequestUri();
    
            if (strpos($requestUri, $storeCode) === false) {
                $targetUrl = $request->getBaseUrl() . '/' . $storeCode;
                header('HTTP/1.1 301 Moved Permanently');
                header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
                header('Pragma: no-cache');
                header('Location: ' . $targetUrl);
                exit;
            }
        }
    
    }
    

    app/code/local/Danslo/RedirectToStore/etc/config.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <global>
            <events>
                <controller_front_init_before>
                    <observers>
                        <redirect_to_store>
                            <class>Danslo_RedirectToStore_Model_Observer</class>
                            <method>redirectToStore</method>
                            <type>singleton</type>
                        </redirect_to_store>
                    </observers>
                </controller_front_init_before>
            </events>
        </global>
    </config>
    

    app/etc/modules/Danslo_RedirectToStore.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <Danslo_RedirectToStore>
                <active>true</active>
                <codePool>local</codePool>
            </Danslo_RedirectToStore>
        </modules>
    </config>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses Boost.Program_options to store and manage its configuration options.
I have an options column which is serialized. I plan to store user preferences
I have a textbox where it stores in a user's option. The possible options
I have an option pane that is displayed upon closing my Application ( windowClosing()
I have an application that allows users to select an option and based on
I have an Android code that contains 2 spinners and a TimePickerDialog. A user
The Background I have the following source code #include <libubuntuone-1.0/u1-music-store.h> #include <libsyncdaemon-1.0/libsyncdaemon/libsyncdaemon.h> static void
I have a Drupal website that has a page at the URL alias of
I have this PHP code that I use to make a dropdown form selection
I have an existing website that uses the same code base, but is deployed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.