I want to display different content depending on the value of X-Forwarded-Host. | Adobe Higher Education
Skip to main content
July 8, 2025
Pregunta

I want to display different content depending on the value of X-Forwarded-Host.

  • July 8, 2025
  • 1 respuesta
  • 429 visualizaciones

■Implementation I want to perform
I want to deliver different content within AEM as a Cloud based on the value of X-Forwarded-Host.
For example, when accessing the URL “https://publish-pxxxx-exxxxx.adobeaemcloud.com/test1/test2.html”:

1. If X-Forwarded-Host: aaa.co.jp, return the content of /content/AAA/test1/test2.
2. If X-Forwarded-Host: bbb.co.jp, return the content of /content/BBB/test1/test2.

 

■What I tried
I added the following settings to the “/dispatcher/src/cond.d/rewrites/rewite.rules” file:


RewriteCond %{HTTP:X-Forwarded-Host} ^AAA.co.jp$
RewriteRule ^/?(.*)$ /content/AAA$1 [PT,L]

 

RewriteCond %{HTTP:X-Forwarded-Host} ^BBB.co.jp$
RewriteRule ^/?(.*)$ /content/BBB$1 [PT,L]

 

However, the above settings did not work properly.
I suspect that the reason might be that X-Forwarded-Host is not recognized by the dispatcher, but I am not certain.

 

■Questions

Please let me know if you know the cause why it does not work, or any alternative solution.

Este tema ha sido cerrado para respuestas.

1 respuesta

Level 4
July 8, 2025

Hi @handa29113846to0o ,

 

I think there may be a problem of dispatcher not forwarding the header.

 

Follow below steps for it - 

 

1. Make sure your CDN/app server passes X‑Forwarded‑Host and that Dispatcher is configured to forward it. In your dispatcher.any, under /clientheaders

/clientheaders { "X-Forwarded-Host" ... other headers ... }

Without this, Dispatcher will ignore your header.

 

2. Declare Virtual Hosts
In each farm or vhost file, explicitly declare the front-facing hostnames:

/farms { /myfarm { /virtualhosts { "aaa.co.jp" "bbb.co.jp" "publish-pxxxx-exxxxx.adobeaemcloud.com" } ... } }

Dispatcher uses /virtualhosts to pick matching farms.

 

3.  Add Rewrite Rules Based on X‑Forwarded‑Host
In your conf.d/rewrites/rewrite.rules (or appropriate vhost file), use this exact syntax:

 

RewriteCond "%{HTTP:X-Forwarded-Host}" "^aaa\.co\.jp$" RewriteRule "^(.*)$" "/content/AAA$1" [PT,L] RewriteCond "%{HTTP:X-Forwarded-Host}" "^bbb\.co\.jp$" RewriteRule "^(.*)$" "/content/BBB$1" [PT,L]
  • You must wrap the header lookup in quotes ("%{HTTP:...}").
  • Escape dots (\.) in domains.
  • Use [PT,L] flags so Dispatcher treats the rewritten path as a proxied request.
July 9, 2025

Hi @shivamkumar 

 

Thank you for your response.

 

I followed each step as below, but it didn’t work.
Is my method incorrect?

 

>1. Make sure your CDN/app server passes X-Forwarded-Host and that Dispatcher is configured to forward it. In your dispatcher.any, under /clientheaders
(1) I created the file dispatcher/src/conf.dispatcher.d/clientheaders/PJname_clientheaders.any with the following content:

"X-Forwarded-Host"


(2) I added an include directive in dispatcher/src/conf.dispatcher.d/clientheaders/clientheaders.any so that the newly created file can be loaded.

 

>2. Declare Virtual Hosts
I created the file dispatcher/src/conf.dispatcher.d/virtualhosts/PJname.any with the following content:

"aaa.co.jp" "bbb.co.jp"

 

>3. Add Rewrite Rules Based on X-Forwarded-Host
I updated the conf.d/rewrites/rewrite.rules file with the content you provided.

Below are my thoughts after following your instructions and verifying further:

In order to confirm that X-Forwarded-Host was valid, I added the following code to the rewrite.rules file, and the content was displayed accordingly:

#RewriteCond %{HTTP:X-Forwarded-Host} ^publish-pxxxx-exxxxx.adobeaemcloud.com$ #RewriteRule ^/?(.*)$ /content/xxx/jp/ja/xxxx.html$1 [PT,L]


Therefore, I believe that X-Forwarded-Host is being recognized.

Also, instead of testing with curl, I verified by accessing through a browser.
This means that without manually setting X-Forwarded-Host: publish-pxxxx-exxxxx.adobeaemcloud.com, the RewriteRule was still applied.
I assume that this is because the Adobe CDN automatically adds X-Forwarded-Host: publish-pxxxx-exxxxx.adobeaemcloud.com when a page is accessed.
In that case, there is a possibility that the manually set X-Forwarded-Host: aaa.co.jp for testing the current configuration is blocked by the Adobe CDN.
However, I have no evidence or solution to back this up at the moment.

 

Do you know anything about this?

 

Regards,