0

Modx and Friendly URLs


08
Apr


Modx, FURLs, Articles

How to set-up Friendly URLs (FURLs) in Modx Revolution and Articles.

Note that the information in this post is based on Revo 2.2.11. There is every likelihood that it will work in earlier and also later versions, but please expect there to be differences. I will periodically update it as I move forward with versions of Revo that I use.

First, an example to show the difference between a standard Modx url and the "friendly" version that will be in place by the end of the steps below:

Default: http://rgissing.com/index.php?id=2

Friendly: http://rgissing.com/blog/

There are a number of steps involved and it is likely that the site (or at least some links) will be unavailable for a time during the process. The order is not critical, except for the first step - but following this procedure exactly will minimize downtime.

Change the Articles URL format

If you are not using Articles or you are happy with the default you can skip this step.

Navigate to the Articles container and click on the Advanced Settings tab. At the bottom of this page is the Articles URL Format setting which has a default setting of:

%Y/%m/%d/%alias/

that produces URLs like:

http://www.mydomain.com/articles/2014/02/06/title-of-an-article/

Personally, I do not want the date as part of the URL and so I have changed it to:

%alias/

It can be anything that you deem appropriate. %alias is the value of the Alias (Permalink) field on each Articles document. If you are going to use friendly URLs then each document should have this field filled in before they are turned on. The alias can be whatever you want but I use a format of 3-5 words separated by dashes (eg modx-and-friendly-urls). Make sure each alias is unique.

If you have already filled in the Alias field at the time you change the Articles URL Format then the change:

will only affect new Articles, unless you change the alias or unpublish and then republish old articles, which will then regenerate their URL to the new format.

from the Help Text

Create an Alias for each resource

As well as creating an alias for each Articles document (as described above), all other documents need to have aliases created. This field is called the Resource Alias. Use the same 3-5 words method as described above to create these also.

Update the Friendly URL system settings

There are a number of system settings that need to be changed for friendly URLs. Navigate to the System / System Settings tab and then select the Friendly URL filter. A page similar to:

Friendly url settings changes

will be displayed. Change the three settings highlighted above from No to Yes.

Edit any templates

Place the following within the <head> section of all the templates that you use (or better, in the standard header chunk you use across the site):

  

Modify .htaccess

When Modx is installed a file ht.access is created in the root of the install. In order to complete the steps required to turn on Friendly URLs, this must be renamed to .htaccess and edited.

In the example below, the highlighted lines must be uncommented (by removing the leading #) and edited to include your base domain.

RewriteEngine On
RewriteBase /

# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^rgissing\.com [NC]
RewriteRule (.*) http://rgissing.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.rgissing\.com [NC]
#RewriteRule (.*) http://www.rgissing.com/$1 [R=301,L]

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Remove .html

Optionally, you may want to remove the trailing .html from your Furls. There are two ways to do this. If your document is flagged as a container, this will happen automatically. Otherwise, you will need to change the relevant entry in the Content Types menu option from .html to either a blank or / - depending on your preference.

Clear the cache

If necessary, clear the cache.



Add a Comment