Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

provide 301 redirect in aem 6.5

Avatar

Level 7

Hi,

 

I know Out of the box AEM "redirectTarget" page property does "302" redirect. I am really not sure how AEM doing internally.

 

Client requirement is to have option for both "301" and "302". 

I saw following as options ( more solutions and best solutions are welcome)

http://www.sgaemsolutions.com/2018/

 

http://adobeaemtips.blogspot.com/2017/10/aem-page-redirect-sling-model.html

 

Please let me know, if these are needed or does AEM 6.5 will take care of redirect status if I have "redirectStatus page property value as "301" or "302" or any other solutions.

 

Thanks,

Sri

 

1 Accepted Solution

Avatar

Correct answer by
Employee

This redirection of request URLs in AEM can be configured at the Sling level, typically in the mapping configuration under /etc/map node. There are two ways of changing the status code:

 

1) By sling:status property

 

You can use sling:status property to set a specific status code for a particular redirection. Here is an example:

 

/etc/map

      +-- http

           +-- example.com.80

           |    +-- sling:redirect = "http://www.example.com/"

           |    +-- sling:status = "301"

 

Please check the document [0] for more details.

 

[0]: https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html

 

 

2) Via OSGI configuration

 

Another way, which really sets the default for all redirection, is to configure the status code at the OSGi bundle level. In the OSGi console, browse the the Configuration page and locate: “Apache Sling Resource Resolver Factory” and change the redirect status field to whatever status code is appropriate.

View solution in original post

13 Replies

Avatar

Community Advisor

Hi, 

 

We can handle easily at dispatcher level by passing R=301 to the redirect rules.

 

Ex:

RewriteRule (.*)$ https://%{SERVER_NAME}$1/ [R=301,QSA,L]

RewriteRule ^/test.html /test.html#anchor [NE,R=301,L]

Avatar

Correct answer by
Employee

This redirection of request URLs in AEM can be configured at the Sling level, typically in the mapping configuration under /etc/map node. There are two ways of changing the status code:

 

1) By sling:status property

 

You can use sling:status property to set a specific status code for a particular redirection. Here is an example:

 

/etc/map

      +-- http

           +-- example.com.80

           |    +-- sling:redirect = "http://www.example.com/"

           |    +-- sling:status = "301"

 

Please check the document [0] for more details.

 

[0]: https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html

 

 

2) Via OSGI configuration

 

Another way, which really sets the default for all redirection, is to configure the status code at the OSGi bundle level. In the OSGi console, browse the the Configuration page and locate: “Apache Sling Resource Resolver Factory” and change the redirect status field to whatever status code is appropriate.

Avatar

Community Advisor

@sreenu539 
You can achieve it by using etc/map. Like mapping the input request and redirecting to the destination output page.
Below is an example which might help you:

https://aemsimplifiedbynikhil.wordpress.com/2020/08/26/shortening-of-url-using-etc-map/

Thanks,
Nikhil

Avatar

Level 8

Hi @sreenu539 

Both solutions will work, choosing one on others depends on the requirements if you have hundreds of pages and want to give control to the content authors then selecting this at page property level will help, you do not need to request TechOps guys to add redirection for every page.

If you what pages you want to redirect then I prefer rewrite URL's is the best solution.

Avatar

Level 2

Hi,

I have around 1000 pages which is something like this-

source page- content/abc/content/at/de/test/insights/articles/equity/2020/robotics-automation-at.html

I want to implement 301 redirect 

target page- content/abc/content/at/de/test/insights/articles/equity/2020/robotics-automation.html

 

how can I implement this.

Avatar

Community Advisor

We had similar use case and followed below process:

http://www.sgaemsolutions.com/2020/01/handing-301-redirection-in-aem-using.html 

 

This way, we could manage all the redirects from Author itself.

Avatar

Level 2

Hi @Siva_Sogalapalli ,

 

Did you use ACS common Redirect Map Manager or through dispatcher config only?

bcz I can see redirect map manager has some limitation which is mentioned in that article.

Limitations of 301 Redirects in Redirect Map Manager:

301 Redirect Map is really a cool feature but it has some limitations.

  1. This is one to one mapping and we can not manage a regex here. So if we have 1000 of URL’s need to redirect in a particular pattern you can not manage in Redirect Map. For this, you have to manage it in Apache level. So create a file and add all the regex redirect URL’s like shown below.

RewriteRule ^/en/index(.*)html$  /en/home.html [R=301,L]

Include the file in the rewrite file of a particular website.

Avatar

Community Advisor

We have followed below steps: 

1. Used ACS common Redirect Manager to mange all the redirects

2. Publish the same to the publisher

3. Wrote shell script  & placed on dispatcher which will connect to the publisher and download the redirects map and save at dispatcher level.

4. Added Rewrite rules at dispatcher level to pick redirects map and redirects accordingly.

 

Eg: 

SivaPrasadReddyS_0-1637071222098.png

 

Note: We wanted to give the flexibility to the authors where they can manage redirects source & target from author instance itself so we went with this approach.

 

In your case, I think you can even try rewrite rule with regular expression at Apache itself if you know the pattern of url changes. 

 

 

 

 

 
 

Avatar

Community Advisor

Nope @Anoop345 , You don't need to create redirects-map.txt in author instance.

 

1. If you follow http://www.sgaemsolutions.com/2020/01/handing-301-redirection-in-aem-using.html , redirects map txt will be generated automatically on author instance, and then publish the same redirects map page so that redirect map.txt can be accessed with publish url.  

SivaPrasadReddyS_0-1637829117400.png

 

2. Then write custom script and place it on dispatcher. The scripts will download the redirectsmap.txt file from publisher and store it in dispatcher itself. 

3. Point the dispatcher configuration to redirectsmap.txt file which is stored in dispatcher level.

 

Note: These are general steps but you don't have to follow exactly same and you can customize flow as per your comfort. 

 

Hope this will answer your questions. please let me know if you need any further help on this. 

 

Avatar

Level 2

Hi Siva,

              I am trying to provide the content authors the Redirect capabilities. I am using "Redirect Manager" for the same. I am looking for the script, we need to place at the dispatcher level.  I am not able to see the map file in crx de. Please advise, where I should get it ?? 

 

AEM 6.5

ACS Commons Redirect Manager.

 

Thanks for your help.

 

Regards

Mohammed

 

 

Avatar

Community Advisor

@moalam , Are you following the steps mentioned in the previous reply or you're trying any customised flow to achieve the same?

If you're following above steps for the same, you can get the script from one of the below resources. 

https://adobe-consulting-services.github.io/acs-aem-commons/features/redirect-map-manager/index.html

http://www.sgaemsolutions.com/2020/01/handing-301-redirection-in-aem-using.html 

 

Hope this helps, please let us know if you still see an issues. 

Avatar

Level 2

Hi @Siva_Sogalapalli ,

 

Thanks for the reply actually I am trying to use "Redirect manager" not the "Redirect Map Manager". In redirect manager, I am trying to update the dispatcher.

 

 

Regards

Mohammed