Understanding Weblinks

First in a series of articles on MODX Weblinks.


This is the first in a series of articles about understanding, creating, and updating Weblinks. In this one, we'll take a look at how Weblinks work and what they look like in the database.


MODX logo

What's a WebLink?

It's easy to use a Weblink without knowing what it really is. All you need to do is set the Title, Alias, and Menu Title and put a URL, Resource ID, or link tag in the Weblink field. When the user clicks on the Weblink's link in a Wayfinder menu, for example, the user will be forwarded to that URL.


In older versions of MODX, using a Resource ID in the Weblink field doesn't work. That option was added in MODX 2.2.5. In versions before that, only a URL or a link tag will work.


Underneath the hood, a Weblink is really just a particular kind of resource that contains a URL, link tag, or Resource ID in its content field. Whatever you put in the Weblink field in the Manager actually gets saved in the resource's content field in the database.

In the database, a Weblink is saved in the same table as Resources and Articles (modx_site_content). Because, like an Article, the modWebLink object extends the modResource object, it has all the same fields as a Resource. Surprisingly, it has no extra fields. If you look at a Weblink in the database, it will look just like all the other resources except that it will have a URL, ResourceID, or link tag in the content field, modWebLink in the class_key field and a 301 redirect message in the properties field. The last two of these get there automatically when you save a Weblink in the Manager, so you don't have to worry about them unless you're creating a Weblink in code.


Why Use a Weblink?

Suppose you want the same Resource in two or more places in your menu system. You could create two identical pages, but then you'd have to maintain them both. Worse yet, you risk being penalized for duplicate content, since the two pages will look identical to an indexing service like Google.

When you use a Weblink for one of the pages, however, MODX will redirect users from the Weblink to the other page with a "HTTP/1.1 301 Moved Permanently" redirect. This will keep any indexing service happy. The redirect code and message are stored in the properties field of the weblink, so they can be changed (see the note below), but I've never seen a situation where the default: 301 - Moved Permanently code is not what you want.


In the Manager, and in these articles, the term used for this MODX object is "Weblink". Be careful, though. In code it's called modWebLink. Notice that in this case the "L" is capitalized.


If you create a Weblink in the Manager, you can see (and modify) the redirect type in the Response Code field on the Settings tab of the Create/Edit Weblink panel. The Manager's JavaScript will fill in the default Response code for you (HTTP/1.1 301 Moved Permanently). The value should be in this exact form in order for the browser to recognize it. You can see a list of the possible response status codes here


Coming Up

In the next article, we'll look at how to create a new Weblink in code.



For more information on how to use MODX to create a web site, see my web site Bob's Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at Hosting.com (formerly A2 Hosting). (More information in the box below.)



Comments (0)


Please login to comment.

  (Login)