npx claudepluginhub friendsofredaxo/claude-marketplace --plugin redaxo-yrewriteThis skill uses the workspace's default tool permissions.
YRewrite supports two layers of redirects:
Guides Next.js Cache Components and Partial Prerendering (PPR): 'use cache' directives, cacheLife(), cacheTag(), revalidateTag() for caching, invalidation, static/dynamic optimization. Auto-activates on cacheComponents: true.
Processes PDFs: extracts text/tables/images, merges/splits/rotates pages, adds watermarks, creates/fills forms, encrypts/decrypts, OCRs scans. Activates on PDF mentions or output requests.
Share bugs, ideas, or general feedback.
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):
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('yrewrite_forward'));
$sql->setValue('status', 1);
$sql->setValue('clang_start', 1);
$sql->setValue('domain', 'www.example.com');
$sql->setValue('url', 'old/path'); // source: matches request path (no leading /)
$sql->setValue('type', 'extern'); // 'article', 'extern', 'media'
$sql->setValue('target', 'https://new.example.com/landing');
$sql->setValue('redirection_code', 301);
$sql->setValue('description', 'Old marketing landing');
$sql->insert();
For type: article, set target to the article ID and the redirect resolves to its current URL (so it survives URL changes downstream).
For media redirects (e.g. moving a PDF to a new path), use type: media and set target to the new media filename in the mediapool.
YRewrite ships an .htaccess template in redaxo/data/addons/yrewrite/.htaccess. 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
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)articleredirection_code: 0)For passthrough (slug stays visible, content from target article), set redirection_code: 0. YRewrite re-routes internally without sending a redirect to the browser.
clang_start on multi-language sites – the forward then matches all languages and may redirect users out of their chosen language..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.