Last active
August 12, 2024 17:23
-
-
Save M-O-Z-G/8d51bb1ce54f83a526c137f5dd7fb886 to your computer and use it in GitHub Desktop.
Removing `site` directory from ProcessWire default paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use `sanitizedUrl($config->urls->templates)` instead pure `$config->urls->templates` in your template php files. | |
function sanitizedUrl($path) { | |
return str_replace('/site', '', $path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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