Two 301 redirections are happening whenever a 301 redirect rule is applied from AEM dispatcher | Community
Skip to main content
AMANATH_ULLAH
Community Advisor
Community Advisor
October 3, 2022
Solved

Two 301 redirections are happening whenever a 301 redirect rule is applied from AEM dispatcher

  • October 3, 2022
  • 1 reply
  • 951 views

We have implemented 301 redirections by adding rewrite rules to our dispatcher configurations. We see two 301 redirects are happening in network tab in our site whenever the 301 rewrite rules gets executed

 

For example in case of the page https://abcd.com/content/abc/us/en/support.html URL is hit in the browser, First 301 is happening to http://abcd.com/support.html (Where the redirect is happening to HTTP instead of HTTPS) Then next redirection happens to https://abcd.com/support.html (First request is going to HTTP and then to HTTPS) Instead it should directly redirect to https site. We are trying to check why the first redirection is happening to HTTP.

Below is the rewrite rule we added in dispatcher configurations

RewriteRule ^/content/abc/us/en/(.*)(.html)$ /$1.html [R=301]

Note: We are using AEM as a cloud service

Any help is highly appreciated

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

This is because your internal dispatcher is http, where when you redirect the page via 
RewriteRule ^/content/abc/us/en/(.*)(.html)$ /$1.html [R=301], you are actually redirecting the users to the http endpoint.|

it will redirect 
http://abcd.com/support.html 

https://abcd.com/support.html (because an apache rule or Azure frontdoor rule forces all requests to go to HTTPS)

 

to solve this problem, you can include the https protocol in the redirect target

RewriteRule ^/content/abc/us/en/(.*)(.html)$ https://%{HTTP_HOST}/$1.html [R=301]

 

Ideally, you should set an environment variable that includes the protocol and hostname,

https://%{HTTP_HOST}/$1

 

1 reply

BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
October 3, 2022

This is because your internal dispatcher is http, where when you redirect the page via 
RewriteRule ^/content/abc/us/en/(.*)(.html)$ /$1.html [R=301], you are actually redirecting the users to the http endpoint.|

it will redirect 
http://abcd.com/support.html 

https://abcd.com/support.html (because an apache rule or Azure frontdoor rule forces all requests to go to HTTPS)

 

to solve this problem, you can include the https protocol in the redirect target

RewriteRule ^/content/abc/us/en/(.*)(.html)$ https://%{HTTP_HOST}/$1.html [R=301]

 

Ideally, you should set an environment variable that includes the protocol and hostname,

https://%{HTTP_HOST}/$1