301 Redirect not working on Cloud | Community
Skip to main content
Love_Sharma
New Participant
May 7, 2025

301 Redirect not working on Cloud

  • May 7, 2025
  • 5 replies
  • 1863 views

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

5 replies

kautuk_sahni
Employee
July 1, 2025

@love_sharma 

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!

Kautuk Sahni
Employee
May 9, 2025

AEM documentation and troubleshooting refer specifically to correct handling of virtual hosts and hostname/redirect processing:

Solution

Use a relative URL in your redirect

This is what you're attempting, and should work:

RewriteRule ^/xyz/?$ /abc [R=301,L]

or

RewriteRule ^/xyz(/.*)?$ /abc [R=301,L]
  • By specifying a relative URL (/abc), the client’s browser should stay on the same domain, using the Host header of the original request.

Check for RewriteBase and VirtualHost config

  • Make sure you are running this rule inside the correct <VirtualHost> block for qa.myproject.com.
  • If you are, and still getting a redirect to https://publish-domain/abc, there may be another RewriteRule firing first, or your dispatcher farm/vhost (or AEM itself) is configured to externalize/resolve using the publisher’s DNS name.
  • Try enabling RewriteLog to trace what rule is being executed.

Avoid hardcoded domains

  • Never use absolute URLs with internal domains in the rewrite/redirect rules.
  • Always use relative paths only unless you want to specifically redirect to another domain.

Check /externalizer config in AEM

  • If you use AEM's Externalizer service in custom code or config, ensure the publish environment is registered with the correct external/public base URL, not the internal publish hostname.

Sling Mappings

  • Sling mappings are not usually involved for this particular redirect. If you do have custom mappings, make sure none are producing absolute URLs with internal hostnames for /abc.

TL;DR

  • Keep your redirect rule as:
    RewriteRule ^/xyz/?$ /abc [R=301,L]
  • Check that this is inside the VirtualHost config for your public domain.
  • Make sure there’s no earlier rule or AEM config causing an absolute URL with the internal publish host.
  • You do NOT need a full absolute URL for the redirect target, unless you are explicitly redirecting across domains.

References:

AmitVishwakarma
New Participant
May 7, 2025

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

Love_Sharma
New Participant
May 8, 2025

@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]

New Participant
May 7, 2025

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.

konstantyn_diachenko
New Participant
May 7, 2025

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/content-delivery/pipeline-free-url-redirects on your project.

 

Best regards,

Kostiantyn Diachenko.

Kostiantyn DiachenkoCheck out AEM VLT Intellij plugin
Love_Sharma
New Participant
May 7, 2025

@konstantyn_diachenko I already tried this approach. This redirect me to ${http_host}/abc, not resolving https_host.

konstantyn_diachenko
New Participant
May 7, 2025

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.

Kostiantyn DiachenkoCheck out AEM VLT Intellij plugin