Skip to content

Instantly share code, notes, and snippets.

@sepiariver
Last active December 21, 2017 12:17
Show Gist options
  • Save sepiariver/fa524dd5480ffe1f0a59 to your computer and use it in GitHub Desktop.
Save sepiariver/fa524dd5480ffe1f0a59 to your computer and use it in GitHub Desktop.
Plugin to fix trailing slash inconsistencies in MODX Resource URIs
<?php
/**
* Steps to implement
* 1. Set HTML content-type default suffix to '/'
* 2. Ensure Resources have isFolder = 1 as default
* 3. If you still have issues with Resources being routed to the URI without a trailing slash,
* create this Plugin and enable it 'OnWebPageInit'.
**/
if ($modx->event->name !== 'OnWebPageInit') return;
if (substr($_SERVER['REQUEST_URI'], -1) !== '/') $modx->sendRedirect($_SERVER['REQUEST_URI'] . '/', array(
'responseCode' => 'HTTP/1.1 301 Moved Permanently'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment