3

I'm having problems creating an internal redirect using MenuItems.

I've created a menu item called 'sale'. I've found the menu item in the database and the alias is 'sale'. I've set the url to /mycomponent?id=3 and published the menu item, but /sale causes a 404 instead of loading /mycomponent?id=3.

I noticed that there is no alias for external urls, and that there was some debate over if it was needed for internal urls:

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=29264

I don't want to use the Redirect component for this. We have three environments, and that would involve setting up a redirect in each environment. If I can get the menu item working then it can be transferred between environments.

Is there a way to setup an internal url using menu items? If so how is that accessed by alias?

  • What is it that you're trying to link to? For internal links use System Links -> Menu Item Alias as the menu item type. – matty Jun 10 '15 at 15:13
  • Its a link to a component, such as /mycomponent?id=3. Menu Item Alias doesn't allow me to enter a custom url, such as the 'id=3' part – ContextSwitch Jun 10 '15 at 20:17
  • I am confused. What are you trying to do? What is the relationship of google.com with the sale menu item? – FFrewin Jun 10 '15 at 23:17
  • google was just an example, sorry for the confusion. I've updated the question text to say /mycomponent?id=3. What I'm trying to do is have a menu item, /sale that redirects to /mycomponent?id=3 using only relative urls. The relative url requirement means that the Redirect component won't work. – ContextSwitch Jun 11 '15 at 13:08
5

The solution I went with was to add the parameter (id) to the view's default.xml:

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="mycomponent">
        <message>mycomponent message</message>
    </layout>
    <fields name="request">
            <fieldset name="request">
                <field
                    name="id"
                    type="text"
                    label="ID"
                    description="The ID of the item as it appears in the url"
                    default="1"
                >
                </field>
            </fieldset>
        </fields>

</metadata>

This way, I was able to create a menu item with an alias of 'sale', and select my component. Then I'd enter '3' in the id field, and /sale would render the same as if I had hit /mycomponent?id=3.

1

You can't achieve what you are trying to without using some sort of redirect process.

That is the URL [site]/sale needs to be redirected www.google.com (for example)

Using External Links will not solve it - because they are exactly what they are, equivalent of having a href tag as one of your menu items.

In Joomla [site]/path are the URLs to Joomla Aricles/content/components.

Therefore, if a content item [site]/sale does not exist (or is not linked to a published menu item) then you will get a 404.

One other way would be to create an Article called Sale, point to it with a standard Menu item and have some re-direct code on that Article.

But this is very ugly way of doing it.

  • Yeah, it would be easier to setup the Redirect component than to add a server redirect every time we need a new one. I'll check the extensions directory to see if i can find anything there. – ContextSwitch Jun 11 '15 at 13:10
1

The question confuses me a little. Not sure what you're wanting, but let me take a shot.

When you pick the menu item type, you get choices based on the components you have installed. For example, if you pick "Single Article" you get to select an article for the menu item to point to.

Now, in the menu item you'll see a terrible mishmash of a URL, beginning with index.php. No biggie, because the only way your visitors will see that is if you don't have any sort of SEF URL creation turned on. That's just the internal representation, not what the users will see.

I'm assuming whatever component you have there works the same way (if it doesn't, find another one because that one's broken). So don't worry about that. The only thing that matters is what Joomla actually writes in the browser (which isn't necessarily what you see in the box).

If you want to completely control what the URL for any given page is, get pretty much any of the SEF URL generators from JED. They all do that.

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.