Using Friendly URLs

Skip to end of metadata
Go to start of metadata

Description:

You can have friendly URLs fully functioning in under two minutes by following a simple four step process:

1) Working .htaccess sample

MODx supplies an ht.access file for you to edit to match your server settings. This file will be ignored by the server until you rename it to .htaccess. The .htaccess file can be anywhere above the MODx installation but the usual location is in the MODX site root (where the Manager directory is). You can also simply create your own .htaccess file in any text editor, paste in the following code, save it in the MODX site root, and edit it accordingly:

  1. change the DOMAINNAME to your domain name in lowercase.
    For me: shawnwilkerson
  2. change the TLD to the com, net, org, info, whatever you have
    For me: com

# Friendly URLs Part
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
# Force all pages to go to www.domain.com for SEO
RewriteCond %{HTTP_HOST} !^www\.DOMAINNAME\.TLD [NC]
RewriteRule (.*) http://www.DOMAINANME.TLD/$1 [R=301,L]
# Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Additional Settings Follow
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
BrowserMatch "MSIE" brokenvary=1
BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
BrowserMatch "Opera" !brokenvary
SetEnvIf brokenvary 1 force-no-vary

/htdocs is fine or /public_html or what ever. your server uses
The .htacess has to be at the same level as the main index.php or above the document MODx is presenting.

Be aware some control panels like to write their own .htaccess just above the site level so the best place to put it is where the home page of the site points to (view image above)
The RewriteBase should end with a /

This works fine for Redhat Linux 5 / Apache setups. If it is not working for you contact your hosting provider -- send them this code and ask them what you need to get it working. The majority of comments have been removed and most of what remains is not required for Friendly URLS to function.

2) Configure MODx Revolution

Next change the settings in the Friendly URLs Area of the System Settings in the System menu of the Revolution Manager to something like the following image indicates.

If you do not see all of Revolution's FURL settings, simply change the "Area" drop-down box to Friendly URL as I did.
You will not find friendly_url_prefix and friendly_url_suffix among the settings in the image below - these have been deprecated in favor of extensions defined by Content Types and container_suffix (for Container Resources with Content Types having a mime_type of text/html).

The use_alias_path setting allows the site to display directory structures.  There are scenarios where all of the documents on the site might appear as directly off of the root, disregarding the paths. In this scenario you can simply choose not to have the paths utilized when Revolution presents the page.
The friendly_alias_urls setting was removed in MODX 2.1+. Enabling friendly_urls implies you are using friendly_alias_urls in 2.1+ and this setting was no longer useful or necessary.

3) Edit your template(s)

Make sure you have the following between the  <head></head> tags:

<base href="[[!++site_url]]" />

4) Clear the MODx Revolution cache

And you're done!

The easiest way to take advantage of using fully qualified Friendly URLs, is to allow MODx Revolution to build the links even within page content. As described at the bottom of resource tag syntax to create links to different resources, is easy as <a href="[[~1]]" title="some title">Some Page</a> . This has the added benefit of being able to move resources around a web project, without needing to fix a bunch of broken links, as MODx Revolution will simply update links created in this manner automatically.

Labels

system system Delete
friendly friendly Delete
url url Delete
furls furls Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.