ModX Revolution Friendly URLs

ModX Revolution Friendly URLs

ModX Revolution Friendly URLs

I have become quite the ModX lover lately, I use it to run my site, as well as a great number of client websites and find that it is extremely speedy, easy to use (from my perspective), and easy to teach.

There are a few things I don’t like about it, but this post is not about that (well… at least not all of them :)).  This post is about SEO and URL Friendliness.

Now ModX has a great built-in way to allow us to have friendly URLs for our content resources, however, by default all HTML content pages are given the .html extension.  While this normally is not a big deal, I am a bit of a stickler when it comes to my URL’s.  I like them with no extension what-so-ever.

So… after much digging around in my site’s settings, I finally figured out how to take care of this.   Here are the steps I took, hopefully it will help you accomplish the same thing.

First and foremost, after you install ModX on your server, make sure to create or update your existing .htaccess file:

RewriteEngine On
RewriteBase /

ErrorDocument 404 /page-not-found

# for now, set the default document to index.htm
# DirectoryIndex index.htm index.php

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

# caching static files
<IfModule mod_headers.c>
    <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|bmp|js|css|swf|woff|svg|ttf|otf|eot)(.gz)?$">
		# To Prevent Caching
		#Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
		#Header set Pragma "no-cache"
		#Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
		# Cache
		Header unset Pragma
		Header unset ETag
		Header set Cache-Control "max-age=31556000, store, cache"
		Header unset Last-Modified
		Header set Connection keep-alive
		Header add X-PoweredBy "o7th Web Design ~ Real Design, Real Development, by Real People ~ "
    </FilesMatch>
</IfModule>
FileETag None
<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresDefault "access plus 1 seconds"
	ExpiresByType text/html M31556000
	ExpiresByType image/gif M31556000
	ExpiresByType image/jpeg M31556000
	ExpiresByType image/png M31556000
	ExpiresByType text/css M31556000
	ExpiresByType text/javascript M31556000
	ExpiresByType application/javascript M31556000
	ExpiresByType application/x-javascript M31556000
	ExpiresByType text/xml M31556000
	ExpiresByType image/svg+xml M31556000
	ExpiresByType application/x-font-ttf M31556000
	ExpiresByType application/x-font-truetype M31556000
	ExpiresByType application/x-font-opentype M31556000
	ExpiresByType application/vnd.ms-fontobject M31556000
	ExpiresByType application/x-font-woff M31556000  
</IfModule>

# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

php_flag zlib.output_compression On
php_value zlib.output_compression_level 9

Now, as you can see it put in a few extras for you, these are to help speed up for site, ensure caching, etc…  the main lines to look for in here are the  re-write rules.  You will notice that we are taking every page request, and sending the to the ModX processor.

Now, the next step to take is to of course turn on the Friendly URLs in our ModX manager, so go ahead and login and get to your ‘System Settings‘ page.  Once there, select ‘Friendly URL‘ from the “Filter by area...” drop-down.

Look for “Use Friendly URL” and change the setting to “Yes“.  I would go a couple steps further here and make sure that the system checks for duplicates, and uses Alias Path.

Once you do that, head over to your ‘System‘ menu once again, and click on ‘Content Types‘.  Now, the default content type for all resource pages is HTML (text/html), so look for HTML, and under “File Extension“, delete out the .html and hit save.

Clear your ModX cache, Remove All Locks, and then browse your site, all your URL’s should now be extensionless 🙂

Hope this helps, and as always… happy coding!

Please note, this has only been tested in ModX Revolution, 2.+

~Kevin

Categories


Let Us Help

Get You Online

Contact Us Today

Important Cookie Information
Our website uses cookies. By continuing to browse the site you are agreeing to our use of cookies. For more details about cookies and their use, please see our Cookie Policy.