Skip to content

Instantly share code, notes, and snippets.

@M-O-Z-G
Last active August 12, 2024 17:23
Show Gist options
  • Save M-O-Z-G/8d51bb1ce54f83a526c137f5dd7fb886 to your computer and use it in GitHub Desktop.
Save M-O-Z-G/8d51bb1ce54f83a526c137f5dd7fb886 to your computer and use it in GitHub Desktop.
Removing `site` directory from ProcessWire default paths
RewriteEngine On
# Redirect /assets to /site/assets
RewriteCond %{REQUEST_URI} ^/assets
RewriteRule ^assets(.*)$ /site/assets$1 [L]
# Redirect /templates to /site/templates
RewriteCond %{REQUEST_URI} ^/templates
RewriteRule ^templates(.*)$ /site/templates$1 [L]
# Block direct access to /site/assets and /site/templates
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /site/(assets|templates)
RewriteRule ^site/(assets|templates)(.*)$ - [F,L]
<?php
// Use `sanitizedUrl($config->urls->templates)` instead pure `$config->urls->templates` in your template php files.
function sanitizedUrl($path) {
return str_replace('/site', '', $path);
}
<?php
$wire->addHookAfter('Pagefile::url', function($event) {
$url = $event->return;
$event->return = sanitizedUrl($url);
});
$wire->addHookAfter('Pageimage::url', function($event) {
$url = $event->return;
$event->return = sanitizedUrl($url);
});
$wire->addHookAfter('Modules::getModuleInfo', function($event) {
$moduleInfo = $event->return;
if (isset($moduleInfo['assetUrl'])) {
$moduleInfo['assetUrl'] = sanitizedUrl($moduleInfo['assetUrl']);
$event->return = $moduleInfo;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment