How Joomla! works with MageBridge URLs
When setting up a MageBridge/Joomla! shop, enabling Joomla! SEF in the Global Configuration is a must. The reason is simple: Magento uses SEF URLs by default, and for MageBridge to succesfully integrate Magento into Joomla!, Joomla! needs to use SEF URLs as well. But because Joomla! and Magento create SEF URLs in different ways, there could be instances where the two mechanisms are conflicting - resulting in Magento 404-errors. This tutorial explains why and how to prevent this.
Menu-Items are generating SEF URLs
To understand how MageBridge uses SEF URLs, it is neccessary to know how Joomla! generates these SEF URLs. Every Joomla! page is actually connected to a Joomla! Menu-Item and the identifier of this Menu-Item - the so-called Itemid - is finally used to load the component in question. Without a Menu-Item, all your SEF URLs will look ugly and you might just as well disable SEF altogether.
Now, the Menu-Item also includes an Alias and this alias is used to construct the actual SEF URL. Say that you have a menu with a Menu-Item Article 1 inside it with an alias article-1. This alias will be picked up to generate the URL:
http://JOOMLA/article-1
Let's say you place a second Menu-Item Article 2 (with an alias article-2) inside the same menu, but configure this Menu-Item to have the first Menu-Item as parent, then the URL will become this:
http://JOOMLA/article-1/article-2
You can see that - because of the hierarchy of Menu-Items - both aliases are used to build the URL.
How Joomla! translates the URL back into a Menu-Item
When Joomla! receives an incoming request from your browser, the requested URL needs to be translated back into Menu-Items as well. The mechanism for this is simple: First Joomla! takes a look at the URL and takes the last segment of this URL as starting point (where each segment is divided by a forward-slash /). In the case of our first example URL, the last segment is article-1. In the case of our second example URL, the last segment is article-2.
Then Joomla! fetches all the configured Menu-Items from the database and runs through them. If the last segment (as found in the URL) matches the Alias of a certain Menu-Item, that Menu-Item is used to display the page. Because both Menu-Items are linked to the Joomla! Articles component (com_content), the Articles-component is called for further actions.
How 404-errors might occur and might be treated
Now, when you call upon an URL that does not exist, Joomla! would take the second-last segment of the URL and try to match that. Take the following URL:
http://JOOMLA/article-1/article-2/non-existing-article
Joomla! first takes up the alias non-existing-article, only to find out that it does not exist. However, the second-last segment article-2 does exist and links to the Joomla! Articles-component (com_content). Now Joomla! calls upon the right Articles-component (com_content) but passes it the non-existent alias - hence the Articles-component will throw a 404-error.
But when the second-last URL-segment would be matched with a Menu-Item linked to another component, the behaviour might be very different. For instance, the component might just ignore the fact that the alias non-existing-article does not exist in the database. It depends entirely on the component what happens here.
Working with the MageBridge Root Menu-Item
The same principles apply to MageBridge. One of the requirements of a SEO MageBridge shop is to have a MageBridge Root Menu-Item configured somewhere in your menus. This Menu-Item points to the Magento homepage within Joomla! (referred to as the MageBridge Root) and ofcourse also has an Alias. Let's say the MageBridge Root Menu-Item is named Shop and its alias is shop. This causes the Magento homepage to become available under the following URL:
http://JOOMLA/shop
MageBridge appends the Magento request to the existing URL
Now, Magento contains numerous pages, and all of these pages are available under SEF URLs. If you have Magento installed under http://MAGENTO/, then for instance the customer login page will be available under the following URL:
http://MAGENTO/customer/account/login
MageBridge will apply the same principle, but swap the original Magento URL with the new MageBridge/Joomla! URL:
http://JOOMLA/shop/customer/account/login
The same applies to a specific Magento product with a Magento URL http://MAGENTO/furniture/my-sofa.html:
http://JOOMLA/shop/furniture/my-sofa.html
Conflicting Menu-Item aliases between different components
Here comes the problem. Let's say you have the MageBridge Root Menu-Item correctly setup, but you create a second Menu-Item pointing to the Joomla! user-login (component com_user) with the MageBridge Root Menu-Item as parent. If this second Menu-Item has an alias customer, then the Joomla! URL will look like this:
http://JOOMLA/shop/customer
But now, when you call upon the URL http://JOOMLA/shop/customer/account/login, then Joomla! will find this second Menu-Item the best match. In other words, not the MageBridge component, but the com_user component will be used to serve the URL. The last two segments account and login are just passed on as extra arguments to this component.
Conflicting Menu-Item aliases within the MageBridge component
The problem also exists when you place other MageBridge Menu-Items (for instance a link to a category or product) underneath the MageBridge Root Menu-Item. Let's say that you place a Menu-Item pointing to a MageBridge category-page with an alias furniture underneath the MageBridge Root Menu-Item. It's URL will become:
http://JOOMLA/shop/furniture
But now when a Magento URL http://MAGENTO/furniture/my-sofa.html is translated to MageBridge, the URL-segment my-sofa will be passed on to the second Menu-Item resulting in a 404-error.
Solution
You can understand that this behaviour is unwanted. Therefor, the advise is to be very careful when working with Menu-Items below the MageBridge Root Menu-Item. It's best to not create Menu-Items underneath the MageBridge Root Menu-Item at all. Perhaps place the Menu-Item in a non-visible menu (in other words, a menu without a module attached to it). Use other Menu-Items (like category Menu-Items) to build your visible hierarchy instead.
Created on Tuesday, 29 November 2011Modified on Tuesday, 29 November 2011
More tutorials in this section
- Setting the MageBridge URLs in Magento
- Disabling user synchronization in MageBridge
- Importing and exporting users
- Using the MageBridgeLinks/JCE-plugin
- Best practices with MageBridge
- Using MageBridge Product Connectors
- Migrating users between Joomla! and Magento
- Using MageBridge stores to load a different Magento theme
- Using the MageBridge Content Plugin
- MageBridge SEO Guide
- Removing MageBridge
- Step-by-step: Adding a custom Magento block
- Managing MageBridge extensions
- How to use URL-suffices with MageBridge?
- Step-by-step: Create a Magento API user
- Step-by-step: Activating MageBridge plugins
- Step-by-step: Creating a MageBridge Menu-Item
- API permissions with MageBridge
- Configuring payment methods in MageBridge
- Using MageBridge modules
- Authentication guide for MageBridge
- Working with MageBridge URL Replacements
- Handling Downloadable Products in MageBridge
- Handling file uploads in MageBridge
- Configuring the MageBridge Root Menu-Item
- Setting MageBridge offline through the database
- How Joomla! works with MageBridge URLs
- Migrating MageBridge from Joomla! 1.5 to Joomla! 2.5
- Using the MageBridge System Plugin
