Configuration of sling:alias | Community
Skip to main content
January 30, 2025
Solved

Configuration of sling:alias

  • January 30, 2025
  • 3 replies
  • 1189 views

Hello,

 

I have a question, I’m currently testing sling:alias because I need to replace some URLs. My question is, when using sling:alias, will the resource resolver automatically return only the paths with the alias? Or will the original path still be valid?

 

What I ultimately need is, if my original path is /content/testing and my alias is /content/testing-alias, I want /content/testing to return a 404 when entering the URL, and only be accessible through /content/testing-alias.

 

I'm asking because someone told me that the normal behavior of the resource resolver is to always return the path with the alias and not the original path, so I’m not sure if that’s true, or if I have an older version that prevents me from seeing this behavior.

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 Shiv_Prakash_Patel

Hi @juan_carlosor1 ,

The sling:alias property in AEM does not completely replace the original path but rather provides an alternate URL for accessing the resource.

Accessing /content/testing-alias : Works as expected (resolves to /content/testing).
Accessing /content/testing directly : Still works (unless restricted manually).

We need to explicitly block access to /content/testing using below approach:

1. Update the Dispatcher Rewrite Rules to prevent access to /content/testing

RewriteCond %{REQUEST_URI} ^/content/testing$ RewriteRule .* - [R=404,L]

2. You can also use Sling Resource Mapping (/etc/map) to redirect or block the original path.

/content/testing: sling:redirectStatus: 404

3. Update ACL - Deny read access to /content/testing in AEM Permissions Console (/useradmin) to enforce a 404 response.

Regards,

3 replies

Shiv_Prakash_Patel
Community Advisor
Shiv_Prakash_PatelCommunity AdvisorAccepted solution
Community Advisor
January 30, 2025

Hi @juan_carlosor1 ,

The sling:alias property in AEM does not completely replace the original path but rather provides an alternate URL for accessing the resource.

Accessing /content/testing-alias : Works as expected (resolves to /content/testing).
Accessing /content/testing directly : Still works (unless restricted manually).

We need to explicitly block access to /content/testing using below approach:

1. Update the Dispatcher Rewrite Rules to prevent access to /content/testing

RewriteCond %{REQUEST_URI} ^/content/testing$ RewriteRule .* - [R=404,L]

2. You can also use Sling Resource Mapping (/etc/map) to redirect or block the original path.

/content/testing: sling:redirectStatus: 404

3. Update ACL - Deny read access to /content/testing in AEM Permissions Console (/useradmin) to enforce a 404 response.

Regards,

Shiv Prakash
AmitVishwakarma
Community Advisor
Community Advisor
February 1, 2025

When you configure sling:alias, the original path will still be valid by default and won't return a 404 unless you explicitly manage the behavior. The sling:alias functionality is primarily used for redirecting URLs, so when you set an alias, AEM will still return the original path unless you add custom logic to handle the 404 scenario.

To achieve the behavior you're looking for, where /content/testing returns a 404 and only /content/testing-alias is valid, you can:

1. Configure Sling Alias: Set up the alias using sling:alias on /content/testing-alias.

2. Add Custom Logic: Implement a custom filter or servlet to intercept requests to /content/testing and return a 404 error, or handle redirection as needed.

Alternatively, you can also use Apache Sling Redirects in the AEM dispatcher or apply a configuration to manage this behavior at the dispatcher level.

This is not an out-of-the-box feature but can be accomplished with the appropriate customization in AEM.

chaudharynick
Level 4
February 3, 2025

Hi @juan_carlosor1 

 

you can use ACS commons redirect map manager(https://adobe-consulting-services.github.io/acs-aem-commons/features/redirect-map-manager/index.html) to set up an alias so that when someone tries to access the alias URL, the user will see the original page and to block the original page, you will need to write dispatcher rule to block the main page like below

 

RewriteRule ^/content/testing\.html$ - [F,L]