RU Русская версия

MODX SEO setup

Removing duplicate pages, setting up redirects, and preparing a MODX site for search engines. Works for MODX Revolution 2 and 3.

  • 9 stepsguide
  • 5 minread

Published updated by Sergey Polyakov

Basic search engine optimization (SEO) for a website on MODX Revolution: one main domain, HTTPS, clean URLs without duplicates, canonical links, a sitemap, robots.txt, and error pages.

The guide works for MODX Revolution 2 and 3. We set up every MODX site we build this way.

The examples use the domain example.com. The screenshots show the MODX manager in Russian; setting names in the text are given in English, as they appear in the English manager.

Redirect from www to non-www or back

Search engines index example.com and www.example.com as two different sites with the same content. To make them treat it as one site, set up a redirect.

In the site root folder, for example /www/example.com/docs/, find the ht.access file and rename it to .htaccess.

The MODX .htaccess file already contains the rules you need; just uncomment the right lines (remove the #):

From www to non-www:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Result: https://example.com

From non-www to www:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]

Result: https://www.example.com

Redirect from HTTP to HTTPS

To move the site to a secure connection (HTTPS), you need an SSL certificate. How to issue one is described in steps 8⁠–⁠9 of our guide Hosting setup.

Open /www/example.com/docs/.htaccess and uncomment these lines:

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Check that the redirect works with the server response checker in Yandex Webmaster or any HTTP status checker.

Enter these four addresses one by one:

example.com
www.example.com
https://example.com
https://www.example.com

If everything is set up correctly, each of the four requests redirects to the main URL. In the screenshot below, that is https://example.com/.

Checking the redirect in a server response tool

Friendly URLs

Install the translit extension to transliterate page aliases. It is needed when page titles are written in Cyrillic or other non-Latin scripts; for a site with English titles you can skip it.

Go to Extras, then Installer, then Download Extras. Type “translit” in the search field, click Download, then Back to Package Manager, and Install.

Open System Settings & Events and make the following changes:

System Settings and Events in the MODX manager

Area: Friendly URL

  1. Container Suffix: leave the value empty.
  2. FURL Alias Real-Time Filter (character restriction method): alphanumeric.
  3. FURL Alias Transliteration: russian (for Russian titles).
  4. Use Friendly URLs: Yes.
  5. Strict Friendly URLs: Yes.
  6. Check for Duplicate URIs Across All Contexts: Yes.
  7. Use Friendly Alias Path: Yes.

Area: Site

  1. URL Scheme: abs

Area: Gateway

  1. Strict Request Method: Yes
URL settings in the MODX manager

Remove .html

To remove .html from the end of URLs, open the Content menu and choose Content Types. In the File Extensions column, delete .html.

Remove the trailing slash

To make inner pages open without a trailing slash, add a three-line rule at the beginning of .htaccess, right after RewriteBase /:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .+/$
RewriteRule ^(.+)/$ /$1 [R=301,L]

If the manager starts redirecting endlessly, rename ht.access to .htaccess in the /manager folder. Its RewriteEngine Off rule will take effect.

Canonical links

Tell the search crawler which page is the preferred one to show in search results. To do this, output the rel="canonical" attribute.

Create a snippet named Canonical with the following content:

Creating the Canonical snippet in MODX
$resourceId = $modx->resource->get('id');
if (!$resourceId) { return ''; }
/** @var string|array $args */
$args = '';
if (!empty($scriptProperties['args'])) {
  $args = $scriptProperties['args'];
  if (strpos(ltrim($args), '{') === 0) {
    $args = $modx->fromJSON($args);
    $args = (is_array($args)) ? $args : [];
    foreach ($args as $k => $v) {
      if (is_string($k) && !trim($k) && is_string($v) && !trim($v)) {
        unset($args[$k]);
      }
    }
  }
}
$canonicalUrl = $modx->makeUrl($resourceId, '', $args, 'full');
return '<link rel="canonical" href="'. $canonicalUrl .'">';

Add the [[Canonical]] tag inside the head of every page.

A simpler way to add a canonical link in MODX is to place this code in the head:

<link rel="canonical" href="[[~[[*id]]?scheme=`full`]]">

Sitemap

To create a sitemap, you need the pdoTools extra. After installing it, create a new resource:

  • Title: sitemap.
  • Alias: sitemap.
  • Template: (empty).
  • Content Type: XML.
  • Check Hide From Menus, Published, Cacheable, and Empty Cache.

Content:

[[pdoSitemap?
  &showHidden=`0`
]]

The &showHidden=`0` parameter keeps resources hidden from menus out of the sitemap.

Creating the sitemap resource
Sitemap resource settings: XML content type

Validate the sitemap with the sitemap analysis tool in Yandex Webmaster and in the Sitemaps report of Google Search Console.

Robots.txt

Create one more resource, filled in the same way as the previous one.

  • Title: robots.
  • Alias: robots.
  • Template: (empty).
  • Content Type: Text.
  • Check Hide From Menus, Published, Cacheable, and Empty Cache.
  • Content:
User-agent: *
Disallow: /index.php
Disallow: /index.html
Disallow: /*?
Disallow: /*.html
Sitemap: https://example.com/sitemap.xml

Check how your pages will be crawled with the robots.txt analysis tool in Yandex Webmaster or the robots.txt report in Google Search Console.

401, 404, and 503 pages

Create a resource:

  • Title: Page not found (404).
  • Alias: 404.

Create two more resources the same way for the 401 and 503 pages.

Go to System Settings.

Area: Site

Enter the resource IDs for:

  • Error Page (404, document not found)
  • Unauthorized Page (401, access denied)
  • Site Unavailable Page (503, site unavailable).
Setting up 401, 404, and 503 pages in MODX

Adding Yandex Metrica web analytics

Add Yandex Metrica to analyze what visitors do on the site, see which channels bring traffic, and judge its quality. For a site that works with customers in Russia, Metrica is the standard choice. Elsewhere, any analytics service works the same way: create a tag and add its code to the site.

  • Go to Yandex Metrica and click Add tag.
  • Enter a name (anything, such as the site name).
  • Enter the site address without the protocol or www, for example example.com.
  • Click Next and fill in the information about your site.
  • In the next step you get the tag code; add it to your site.
Creating a new tag in Yandex Metrica

Setting up the site in Yandex Webmaster

Yandex Webmaster, a free tool from the leading search engine in Russia, makes SEO for a MODX site easier. It lets you track page indexing, see search rankings, and find technical errors. For other markets, set the site up the same way in Google Search Console and Bing Webmaster Tools.

  • Go to Yandex Webmaster and add your site.
  • On the Sitemap files page, add the sitemap created in the Sitemap step.
  • In the search appearance section, open regional settings. Specify the regions where your site operates and add your organization from Yandex Business.
  • In the indexing section, under crawling by Metrica tags, link your Metrica tag. After linking, remember to select the checkbox.
  • Add a feed if your site belongs to one of these categories: doctors, education, service providers, jobs, vehicles, real estate. This can bring extra traffic. Feeds are added in the section for services and offers in search, under feeds and errors.
  • In the search appearance section, open sitelinks and, if needed, rename the links to better match the page content.

More articles

Step-by-step guides: domain, hosting, email, maps, and MODX setup.

All articles

Let’s talk

Need a MODX site with SEO set up from day one? We build corporate websites on MODX and do this setup on every one. We reply within one business day.

  • Emailinfo@studiops.ru
  • Messaging app
  • OfficeBalashikha, Moscow Region, Russia
    Mon–Fri, 8 a.m.–5 p.m. Moscow time (UTC+3)
What can we help with?