Resources

Nice Links Using Friendly URLs

light fare

Friendly URLs

How do we change the default "index.php?id=42" URL for our site's pages to something more friendly, like "about-us.html"?

dennisleahy asked...

So, in ModX, every page has a resource number. If you use the Modx built-in menu system, each menu item is referenced by its resource number, not by URL.

For example, Home/About might use www.mydomain/revo/index.php?a=3 (if that page's resource identifier is "3") instead of my more typical way of calling a url, such as: www.mydomain/revo/about.php.

If I do not use the built-in menu system, I'd like to create a navigation menu system that uses URLs (like the second example), not resource numbers.

Can I do that?

I realize pages will be assigned resource numbers, but do I have to use them? Will I still be able to pick pages from the resource tree on the left, and edit them, publish them, and have the (URL-style) menu system point to the edited/published page?

The Solution:

gissirob says...

Most certainly - using Friendly URLs (FURLs). Here is the official documentation and here is a blog post I wrote about it. (you can ignore the references to the Articles add-on).


What's the Story?

MODX is run from the index.php file, and has to know which resource to load in order to generate the page that was requested. By default, this is with a URL like "domain.com/index.php?id=xx". This is ugly, doesn't give any suggestions about the page being requested, and can't be used to indicate a path to the page. So MODX assigns each resource an "alias" field, which is used when generating menus or individual URLs to create a more friendly URL, "domian.com/alias.html". MODX will calculate a path to the actual page using the alias fields of its parents in the Resource tree like "domain.com/alias1/alias2/alias.html". By default, MODX will create the alias using the "pagetitle" field, or you can enter your own alias. Just remember, this will be part of the page's URL, so it needs to be something that will make a proper URL.

MODX still has to be run with the index.php file. so web server URL rewrites are used to tell the web server to pass anything it doesn't find (like alias.html, which doesn't exist as a file on the server) to index.php?q=alias.htm, or index.php?q=alias1/alias2/alias.html. MODX parses that and determines which resource has that alias.