Add the Forwarded-Host header | Community
Skip to main content
December 17, 2024

Add the Forwarded-Host header

  • December 17, 2024
  • 2 replies
  • 1001 views

How can I add the Forwarded-Host header?
For security reasons, I need to add the Forwarded-Host header to my website, but I have no idea how to implement this.
In the file called rewrite.rules I added the code (dispatcher > conf.d > rewrites > rewrite.rules):

<IfModule mod_headers.c>
    RequestHeader set Forwarded-Host "%{Host}e" env=Host
</IfModule>

But it didn't solve my problem of adding the Forwarded-Host.

2 replies

daniel-strmecki
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 17, 2024

Hi @EvertonSa2,

rewrite rules are added in the mod_rewrite section of your VHOST file. Add your custom header directly under VirtualHost in the VHOST file. For example:

 

# Add Forwarded-Host header RequestHeader set Forwarded-Host "%{HTTP_HOST}e"

 

 

Good luck,

Daniel

December 17, 2024

Mas em qual arquivo exatamente eu adiciono esse trecho de código: 

# Add Forwarded-Host header
RequestHeader set Forwarded-Host "%{HTTP_HOST}e"

Não posso modificar o arquivo default.vhost, porque se eu modifica-lo a pipeline da erro.
Os arquivos que possuo são:
dispatcher > src > conf.d > enabled_vhosts > default.vhost
dispatcher > src > conf.d > enabled_vhosts > custom_headers.conf

dispatcher > src > conf.d > available_vhosts > default.vhost
dispatcher > src > conf.d > rewrites > default_rewrite.rules
dispatcher > src > conf.d > rewrites > rewrite.rules

daniel-strmecki
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 17, 2024

@EvertonSa2 let's please stick to English, so I dont have to Google Translate your question 🙂

You should create your own VHOST file, not edit the default one. It is clearly stated in the AEM archetype: https://github.com/adobe/aem-project-archetype/blob/develop/src/main/archetype/dispatcher.cloud/src/...

Also, you did not mention if you are using AEM on Prem or AEMaaCS. Please refer to the relevant Dispatcher documentation from Adobe. Both are well documented.

 

Good luck,

Daniel

kautuk_sahni
Community Manager
Community Manager
January 7, 2025

@evertonsa2 Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni