/redaxo-yrewrite:yrewrite-redirectsfrom redaxo-yrewrite
Configures redirects and forwards in YRewrite for REDAXO CMS, covering database-managed forwards and .htaccess rules for URL migrations, 301/302 choices, and 404 handling.
Ships in redaxo-yrewrite. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
YRewrite supports two layers of redirects:
rex_yrewrite_forward. Best for editor-managed redirects, vanity URLs, post-launch URL fixes..htaccess / nginx rules – for high-volume redirects that should never hit PHP (legacy domain → new domain, scheme upgrades).Use the database layer when editors should manage entries; use the webserver layer for performance-critical or pre-bootstrap rewrites.
Programmatic creation (e.g. during a migration):
$domain = rex_yrewrite::getDomainByName('www.example.com'); // host name without scheme
if (!$domain) {
// getDomainByName() returns null if the domain isn't configured in YRewrite
return;
}
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('yrewrite_forward'));
$sql->setValue('status', 1);
$sql->setValue('domain_id', $domain->getId());
$sql->setValue('url', 'old/path'); // source: matches request path (no leading /)
$sql->setValue('type', 'extern'); // 'article', 'extern', 'media'
$sql->setValue('extern', 'https://new.example.com/landing');
$sql->setValue('movetype', 301); // 301, 302, 303 or 307
$sql->insert();
// Forwards are matched against a cache file, not the table – rebuild it,
// otherwise the new entry has no effect (the backend does the same after saving)
rex_yrewrite_forward::init();
rex_yrewrite_forward::generatePathFile();
For type: article, set article_id and clang instead of extern; the redirect resolves to the article's current URL via rex_getUrl() (so it survives URL changes downstream).
For media redirects (e.g. moving a PDF to a new path), use type: media and set media to the new media filename in the mediapool.
YRewrite ships an .htaccess template in redaxo/src/addons/yrewrite/setup/.htaccess, which YRewrite → Setup copies to the document root (and overwrites an existing file there). Edit the project's actual .htaccess (in the document root), not the template, to add custom rules. Place site-specific rules above YRewrite's catch-all so they fire first.
Force HTTPS:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Force www:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Migrate old URLs in bulk (use a RewriteMap or a static block of RewriteRules):
RewriteRule ^old-product/red-shoe$ /products/red-shoe [R=301,L]
RewriteRule ^old-product/blue-shoe$ /products/blue-shoe [R=301,L]
For nginx, the equivalents go in server blocks before try_files $uri $uri/ /index.php?$args;:
if ($host = 'example.com') {
return 301 https://www.example.com$request_uri;
}
| Code | When |
|---|---|
301 Moved Permanently | The old URL is gone forever. Search engines transfer ranking signals. Default for content moves. |
302 Found | Temporary – maintenance redirects, A/B testing, geo-routing. Search engines keep the original URL indexed. |
307 Temporary Redirect | Like 302 but preserves the HTTP method on POST. Use for form re-submissions. |
308 Permanent Redirect | Like 301 but preserves the HTTP method. Rare; use 301 unless you need POST preservation. |
In code:
rex_response::sendRedirect($url, 301);
exit; // sendRedirect already exits, but keep this for clarity
/media/ URLsWith YRewrite's .htaccess, a forward whose source starts with media/ never fires – regardless of domain and target type. The .htaccess rewrites every media/… request to the media manager (index.php?rex_media_type=…&rex_media_file=…); unlike the final catch-all rule, these rules have no "file exists" conditions, so they apply whether the file exists or not. Both media_manager and yrewrite hook into PACKAGES_INCLUDED at rex_extension::EARLY, and media_manager boots first because yrewrite requires it. rex_media_manager::init() therefore sends the file – or a 404 for a missing file – and exits before YRewrite resolves forwards (rex_yrewrite::prepare() → YREWRITE_PREPARE → rex_yrewrite_forward::getForward()).
To redirect an old media URL, hook into MEDIA_MANAGER_BEFORE_SEND, which fires at the start of rex_media_manager::sendMedia(), before the 404:
// In your addon's boot.php
rex_extension::register('MEDIA_MANAGER_BEFORE_SEND', static function (rex_extension_point $ep) {
$redirects = ['old-brochure.pdf' => 42]; // media filename => target article ID
$file = rex_media_manager::getMediaFile();
if (isset($redirects[$file]) && !rex_media::get($file)) {
$url = rex_yrewrite::getFullUrlByArticleId($redirects[$file], rex_clang::getStartId(), [], '&');
if ('' !== $url) { // empty if the target article has no URL – keep the normal 404
rex_response::sendRedirect($url, rex_response::HTTP_MOVED_PERMANENTLY);
}
}
});
The rex_media::get() check keeps the redirect inactive as soon as a file with that name is back in the mediapool.
YRewrite triggers an extension point YREWRITE_PREPARE early in the request and sets up the 404 article when no match is found. To log 404s for analysis, hook into RESPONSE_SHUTDOWN:
rex_extension::register('RESPONSE_SHUTDOWN', function () {
if (rex_response::getStatus() !== rex_response::HTTP_NOT_FOUND) {
return;
}
rex_logger::factory()->log('warning', '404 for ' . $_SERVER['REQUEST_URI']);
});
Periodically review the log and convert recurring 404s into forward entries.
Editors can create forwards with custom slugs that resolve to internal articles:
team/alice (vanity)articlearticle_id of Alice's profile, plus clang)movetype; the backend offers 301, 302, 303 and 307)Forwards always answer with a redirect – there is no passthrough code. If the slug should stay in the URL bar, give the article that URL instead ("URL" panel in the article sidebar, type "Custom URL"), or resolve the slug yourself in YREWRITE_PREPARE, which YRewrite calls in the frontend when no article path matched:
rex_extension::register('YREWRITE_PREPARE', static function (rex_extension_point $ep) {
if ('team/alice' === $ep->getParam('url')) {
return ['article_id' => 42]; // optional 'clang'; content is served without redirect
}
return $ep->getSubject();
});
extern target pointing back to its own source URL redirects to itself.domain_id and url (plus query parameters in url); clang only selects the language of the target article for type: article..htaccess that editors should manage – they'll change them in the backend and wonder why nothing happens.Host header. curl -I -H "Host: www.example.com" https://staging.example.com/old/path is your friend.media/… URL – the media manager answers first, the forward never fires. Use MEDIA_MANAGER_BEFORE_SEND (see above).What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/yrewrite-domainsYRewrite domain configuration in REDAXO – mapping hostnames to category trees, multi-language sites, and fetching URLs via rex_yrewrite. Use when the user configures domains, builds multi-domain sites, generates internal links via rex_yrewrite::getFullUrlByArticleId, or troubleshoots URL routing./yrewrite-seoSEO helpers in YRewrite – meta tags via rex_yrewrite_seo, sitemap.xml generation, robots.txt, canonical and hreflang tags. Use when the user adds SEO meta to templates, configures sitemap inclusion, customizes robots.txt, or sets up structured social-share metadata (Open Graph, Twitter cards).npx claudepluginhub friendsofredaxo/claude-marketplace --plugin redaxo-yrewriteOther plugins' skills for the same job