CDN URL is redirecting to AEM Publish URL | Community
Skip to main content
Level 2
March 24, 2026
Solved

CDN URL is redirecting to AEM Publish URL

  • March 24, 2026
  • 2 replies
  • 20 views

I have this rule
RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$     /$1/$2 [R=301,L]

 

Now when i hit with CDN domain then my CDN domain gets converted into AEM publish domain and this is true for all the 301 & 302 redirects. Followed couple of articles and did not worked like by adding {HTTP_HOST}, is any header needed in CDN to support this?

Best answer by AmitVishwakarma

Hi ​@JavedZi 

Your rule: RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ /$1/$2 [R=301,L]

returns a relative redirect (/$1/$2).

Apache then builds the full Location header using the Host it sees on the request.

Right now, your CDN is calling the origin with something like: Host: publish.mycompany.com

So Apache/Dispatcher generates: Location: https://publish.mycompany.com/xx/yy

The CDN just passes that back to the browser > you see publish domain, not CDN domain.

This is exactly the "redirection to the publish service endpoint / wrong host" pattern described in the CDN docs. https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/content-delivery/cdn https://experienceleague.adobe.com/en/docs/experience-manager-learn/foundation/administration/url-redirection

 

1. Fix CDN > origin Host header

In your CDN config, make sure the Host header sent to AEM is the CDN domain (or at least the public site domain), not the internal publish host.

Most CDNs have a setting like:

  • Preserve client Host header / Use incoming host / Override Host header = original request host – turn this on.

After this change, origin requests look like: Host: www.example.com     # or your CDN domain

Now your existing rule: RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ /$1/$2 [R=301,L]

will produce: Location: https://www.example.com/xx/yy

so the browser stays on the CDN/public domain.

 

2. (Optional) If you want explicit absolute URLs

Only if you really need an absolute URL, keep it dynamic:

RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ https://%{HTTP_HOST}/$1/$2 [R=301,L]

This still depends on step 1: CDN must send the correct Host header, otherwise %{HTTP_HOST} will again be the publish domain.

2 replies

HrishikeshKagne
Community Advisor
Community Advisor
March 24, 2026

Hi ​@JavedZi ,

Your CDN URL is redirecting to the AEM Publish domain because the redirect rule does not keep the original domain. When a 301 or 302 redirect runs, Apache uses the servers own hostname unless you tell it to use the incoming Host header. To fix this, update the rewrite rule to include the Host header so the CDN domain stays the same.
No special CDN header is needed just adjust the rule so it keeps the original domain.

 

Hrishikesh Kagane
JavedZiAuthor
Level 2
March 24, 2026

Hi ​@HrishikeshKagne  to keep original host we need to use {HTTP_HOST} right? I tried this as well it did not worked. I guess Host as request header is needed in CDN domain.

AmitVishwakarma
Community Advisor
AmitVishwakarmaCommunity AdvisorAccepted solution
Community Advisor
March 24, 2026

Hi ​@JavedZi 

Your rule: RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ /$1/$2 [R=301,L]

returns a relative redirect (/$1/$2).

Apache then builds the full Location header using the Host it sees on the request.

Right now, your CDN is calling the origin with something like: Host: publish.mycompany.com

So Apache/Dispatcher generates: Location: https://publish.mycompany.com/xx/yy

The CDN just passes that back to the browser > you see publish domain, not CDN domain.

This is exactly the "redirection to the publish service endpoint / wrong host" pattern described in the CDN docs. https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/content-delivery/cdn https://experienceleague.adobe.com/en/docs/experience-manager-learn/foundation/administration/url-redirection

 

1. Fix CDN > origin Host header

In your CDN config, make sure the Host header sent to AEM is the CDN domain (or at least the public site domain), not the internal publish host.

Most CDNs have a setting like:

  • Preserve client Host header / Use incoming host / Override Host header = original request host – turn this on.

After this change, origin requests look like: Host: www.example.com     # or your CDN domain

Now your existing rule: RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ /$1/$2 [R=301,L]

will produce: Location: https://www.example.com/xx/yy

so the browser stays on the CDN/public domain.

 

2. (Optional) If you want explicit absolute URLs

Only if you really need an absolute URL, keep it dynamic:

RewriteRule ^/content/my-project/([a-z]{2})/en/(.+)\.html$ https://%{HTTP_HOST}/$1/$2 [R=301,L]

This still depends on step 1: CDN must send the correct Host header, otherwise %{HTTP_HOST} will again be the publish domain.

Amit Vishwakarma - Adobe Commerce Champion 2025 | 16x Adobe certified | 4x Adobe SME