Skip to content

Instantly share code, notes, and snippets.

@Dmi3yy
Last active May 22, 2018 16:05
Show Gist options
  • Save Dmi3yy/648a0698ca5f1592173bb957f10f1315 to your computer and use it in GitHub Desktop.
Save Dmi3yy/648a0698ca5f1592173bb957f10f1315 to your computer and use it in GitHub Desktop.
Evolution CMS + Laravel Valet
//<?php
$e = &$modx->event;
if ($e->name == 'OnWebPageInit') {
if (strpos($_SERVER['DOCUMENT_URI'], 'laravel/valet') !== false){
$url = $modx->db->escape($_SERVER['REQUEST_URI']);
if (isset($url) && $url !== '/') {
$url = explode('?', $url);
$friendly_url_suffix = $modx->config['friendly_url_suffix'];
$base_url = $modx->config['base_url'];
$site_url = $modx->config['site_url'];
$url = preg_replace('@' . $friendly_url_suffix . '$@', '', $url['0']);
if ($url['0'] === '/') {
$url = preg_replace('@^' . $base_url . '@', '', $url);
}
if (substr($url, 0, 4) === 'http') {
$url = preg_replace('@^' . $site_url . '@', '', $url);
}
$idFromAlias = $modx->getIdFromAlias(rtrim($url, '/'));
if($idFromAlias > 0) {
$modx->sendForward($idFromAlias);
}else{
$_GET['q'] = $url;
$modx->sendErrorPage();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment