Expand my Community achievements bar.

SOLVED

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

Avatar

Level 5

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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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