Hi @love_sharma ,
301 redirect from /xyz to /abc on AEM as a Cloud Service, ensuring it respects the domain (qa.myproject.com or otherwise) and avoids redirecting to the internal publish-domain, follow these specific steps:
1. Use Apache Rewrite Rule with Correct Host Preservation
In your Apache configuration (typically in your vhost or dispatcher rules):
RewriteEngine On
# Match /xyz or /xyz/ and redirect with preserved domain and protocol
RewriteRule ^/xyz/?$ https://%{HTTP_HOST}/abc [R=301,L]
This will:
- Match /xyz or /xyz/
- Redirect to the same host (e.g., qa.myproject.com)
- Use https explicitly (important for Cloud)
- Ensure the redirect is a 301 (permanent)
2. Optional – Force Protocol to HTTPS (Recommended)
If your domain might be hit over HTTP and you want to force HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Place this above your /xyz rule if needed.
3. Do NOT use Sling Mapping for Simple Redirects
You do not need Sling mappings (/conf/global/mappings) for simple path-to-path redirects. These are mostly used for vanity URLs and internal resource resolution.
Final Dispatcher Snippet (Minimal Example)
RewriteEngine On
# Optional: Enforce HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect /xyz to /abc
RewriteRule ^/xyz/?$ https://%{HTTP_HOST}/abc [R=301,L]
If you're using AEM Cloud Dispatcher SDK, add this inside your custom rewrite.rules in conf.d/rewrites.
Regards,
Amit