Hello Community,
Using AEM as Cloud, there are two versions for customer registration with following URLs https://domain/abc and https://domain/xyz. We don't want https://domain/xyz anymore and want to have a 301 redirect to /abc page.
I have a rewrite now RewriteRule ^/xyz\/?(.*)$ /abc [R=301, L] this is working but partially.
When I hit this URL on QA environment https://qa.myproject.com/xyz , it is redirected to https://publish-domain/abc, page is served from AEM publisher. Expected redirection should be https://qa.myproject.com/abc
M I missing anything here ? I have also added sling mapping for https://qa.myproject.com domain under /conf/global/mappings but no luck.
Thanks in advance
Hi @Love_Sharma,
Try to add a host and a protocol to your rule:
RewriteRule ^/xyz\/?(.*)$ ${PROTOCOL}://%{HTTP_HOST}/abc [R=301,L]
In addition, consider implementation of https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con... on your project.
Best regards,
Kostiantyn Diachenko.
@konstantyn_diachenko I already tried this approach. This redirect me to ${http_host}/abc, not resolving https_host.
Hi @Love_Sharma ,
I suggested to use %{HTTP_HOST}, not a ${HTTP_HOST}. The HTTP_HOST is a Apache variable. See that here: https://httpd.apache.org/docs/2.4/expr.html#vars.
Best regards,
Kostiantyn Diachenko.
@konstantyn_diachenko I still see it's not working. In rewrite rule file I have two rules in below sequence, is that something impacting
RewriteRule ^/abc\/?(.*)$ /content/us/en/customer-registration.html [NC, QSA, PT, L]
RewriteRule ^/xyz\/?(.*)$ https:://%{HTTP_HOST}/abc [R=301,L]
Hi @Love_Sharma ,
Your rules are not valid and probably your dispatcher doesn't accept these rules. I wonder how were they deployed.
Mistakes:
- Apache rule flags must not have whitespaces after commas
- You have 2 colons after https
Fixed version:
RewriteRule ^/abc\/?(.*)$ /content/us/en/customer-registration.html [NC,QSA,PT,L]
RewriteRule ^/xyz\/?(.*)$ https://%{HTTP_HOST}/abc [R=301]
Try to deploy these changes.
Best regards,
Kostiantyn Diachenko.
Views
Replies
Total Likes
@konstantyn_diachenko Those are editor copy/paste issue while pasting here. There are no gaps and double colon in the code
Views
Replies
Total Likes
Hi @Love_Sharma ,
I realized that we have a lack of details. We are just guessing. Please, provide information in next format:
1) What request do you do
2) What rule do you expect to handle it
3) What result do you anticipate
4) What result do you actually have
Best regards,
Kostiantyn Diachenko.
Views
Replies
Total Likes
Hi @Love_Sharma ,
I believe the following rewrite rule should be enough:
RewriteEngine On
RewriteRule ^/xyz/?$ /abc [R=301,L]
This rule will work across all domains and redirect /xyz to /abc with a 301 status. It’s sufficient for this type of redirection and doesn't require relying on Sling Mappings.
Thanks.
Thanks.
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
@AmitVishwakarma Thanks for the reply. Rule is still not working. Not sure if below sequence could be an issue
RewriteRule ^/abc\/?(.*)$ /content/us/en/customer-registration.html [NC, QSA, PT, L]
RewriteRule ^/xyz\/?(.*)$ https:://%{HTTP_HOST}/abc [R=301,L]
Views
Replies
Total Likes
AEM documentation and troubleshooting refer specifically to correct handling of virtual hosts and hostname/redirect processing:
This is what you're attempting, and should work:
RewriteRule ^/xyz/?$ /abc [R=301,L]
or
RewriteRule ^/xyz(/.*)?$ /abc [R=301,L]
References:
Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies