4

Here is the list of some default URL.

/customer/account/login
/checkout/cart
/customer/account

Is it possible to change these URL's or rewrite this URL's? I've tried default URL rewrite methods in Magento but it doesn't helped. Please suggest if there some proper methods to do this.

6

Depending on what you are trying to do, you have a few different options here. The first and probably easiest if you are not a developer is to use Magento's built in Rewrite Management (under Catalog at the top in admin). You will probably want to create a custom rewrite, and then depending on what you select under Redirect you will create either a rewrite (browser URL stays with the request redirected to another controller action within the framework) or a redirect (when accessing the URL the browser is forwarded to another page).

If you are more technically minded and want to achieve a rewrite in your own module you can rewrite the controller in question in a similar way to rewriting a block, model or helper. In the config.xml of your module you will need something along the lines of the following:

<?xml version="1.0"?>
<config>
    ...
    <frontend>
        ...
        <routers>
            ...
            <customer>
                <args>
                    <modules>
                        <YourNamespace_YourModule before="Mage_Customer">YourNamespace_YourModule_Customer</YourNamespace_YourModule>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

This will cause Magento to look inside your module before the Mage_Customer module for an equivalent controller to fulfil the request. In the above example it would expect to find the controller in location app/code/local/YourNamespace/YourModule/controllers/Customer/AccountController.php and inside that a loginAction() method action. You will very likely want to extend off the controller class you are rewriting and while other rewriting methods (blocks, models etc) autoload the parent class, this isn't the case with controller, so you need to include the parent class (whatever it may be) as the first line of the new controller file (before you declare the class). For instance:

require_once 'Mage/Customer/controllers/AccountController.php';
class YourNamespace_YourModule_Customer_AccountController extends Mage_Customer_AccountController
{
    public function loginAction()
    {
        ...

So this method will keep the browser URL the same but cause Magento to use your controller action instead of the core methods, what if you want to keep using the same controller but access it using a difference frontend URL? Well there is another type of rewrite Magento offers for doing this which rewrites requests to another URL in the same way as you would achieve using the built in rewrite management. Say you wanted to access the cart page under /checkout/bag instead of /checkout/cart, you would do something like the following:

<?xml version="1.0"?>
<config>
    ...
    <global>
        ...
        <rewrite>
            ...
            <some_unique_string>
                <from><![CDATA[#^/checkout/bag#]]></from>
                <to>/checkout/cart</to>
            </some_unique_string>
        </rewrite>
    </global>
</config>

This would mean you could access the cart page using frontend URL /checkout/bag but have the same module, controller and action as before handle the request.

The last thing you can do is change the modules frontName by defining a new frontName in your module for a core module. As third party modules are always loaded after core modules the frontName you defines will be used instead of the one defined by the core module. If you want to change the frontName of another third party module you can just make your module depend on the other third party module which will cause it to load last and this use your frontName (without having modules depend on other modules they just load in alphabetical order). So in app/etc/modules/YourNamespace_YourModule.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <YourNamespace_YourModule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                ...
                <Mage_Customer /> <!-- you don't actually need this as core modules always load before custom modules -->
                <SomeOtherNamespace_SomeOtherModule />
            </depends>
        </YourNamespace_YourModule>
    </modules>
</config>

And the frontName change again in the module config.xml:

<?xml version="1.0"?>
<config>
    ...
    <frontend>
        ...

        <routers>
            ...
            <customer>
                <args>
                    <frontName>yourfrontname</frontName>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

Which would require you to access /customer/account/login instead at URL /yourfrontname/account/login.

  • @Good explain Jonathan.... Upvote from me – Amit Bera Sep 4 '14 at 13:38
1

This module does exactly what you're looking for - it allows you to modify the default urls from e.g. customer/account to client/backend:

https://github.com/magento-hackathon/Hackathon_CustomUrls

  • Please avoid link only answers.Put a short note what those links does. – Rajeev K Tomy Sep 4 '14 at 12:29

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.