Expand my Community achievements bar.

SOLVED

AEM shortening URLs

Avatar

Level 3

Hi,

We did the URL shortening for the site https://www.test.com/content/test/en_us/test.html

So the URL now is https://www.test.com/en_us/test.html but we are still able to access https://www.test.com/content/test/en_us/test.html is this expected behaviour or still we eradicate the /content path fully?

Thanks,

Nivetha Selvakumar

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @nivethaS ,

When you implement URL shortening in AEM, it is common to have the original long URLs still accessible. This is expected behavior as it ensures backward compatibility and avoids breaking existing links. However, for a more seamless user experience and to avoid duplicate content issues (which can affect SEO), it is generally advisable to enforce the shortened URLs and redirect the long ones to their shorter counterparts.

Here’s how you can fully eradicate the /content path and ensure users are only accessing the shortened URLs:

Implementing URL Redirection in AEM

  1. Create a Sling Mapping Configuration: Use the Apache Sling Resource Resolver Factory configuration to create a mapping rule. This will map the long URL to the short URL.

    • Go to AEM Web Console: http://<AEM-HOST>:<PORT>/system/console/configMgr
    • Search for "Apache Sling Resource Resolver Factory".
    • Add the following configuration under the sling:match and sling:redirect properties:

 

{
  "/content/test/en_us/test.html": "/en_us/test.html"
}
​

 

    • This will internally map the long URL to the short URL.
  1. Configure URL Rewriting Using URL Mapping: Create an etc/map configuration in AEM to handle URL mapping.

    • Navigate to CRXDE Lite: http://<AEM-HOST>:<PORT>/crx/de/index.jsp
    • Create the following structure if it doesn’t exist:

 

/etc
  /map
    /http
      /test.com
​
- Under `/test.com`, create a node named `sling:Mapping` with the following properties:
  - `sling:match = "/content/test/(.*)"`
  - `sling:redirect = "/$1"`

 

 

Setup Apache Rewrite Rules: If you are using an Apache HTTP server as a front end to AEM, you can set up rewrite rules to ensure any access to the long URL is redirected to the short URL.

Add the following rewrite rules to your Apache configuration:

 

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/content/test/
RewriteRule ^/content/test/(.*)$ /$1 [R=301,L]

 

  1. This rule will redirect any request that matches /content/test/... to /....

Verification

  1. Testing Redirects: Test the configurations by accessing the original long URL. It should automatically redirect to the shortened URL.

  2. Check Logs and Monitoring: Monitor your AEM logs and web server logs to ensure that the redirections are working as expected and there are no issues.

Notes

  • SEO Considerations: Using 301 (permanent) redirects ensures that search engines understand the move and update their indexes accordingly.
  • Cache Management: If you are using a CDN or caching layer, ensure the cache is purged or updated to reflect these changes.
  • Testing: Perform thorough testing in a staging environment before deploying to production.

By following these steps, you can ensure that users are always directed to the shortened URLs and the original long URLs are properly redirected, thereby eliminating access to the /content path.

View solution in original post

4 Replies

Avatar

Community Advisor

Hi, 

It depends on how you implement it. Can you provide more insights? 



Esteban Bustamante

Avatar

Community Advisor

@nivethaS 

 

It depends on your usecase but it's generally recommended to keep the original URL accessible, as it can be useful for various purposes, such as:

Maintaining backward compatibility for existing links or bookmarks
Allowing direct access to the content for specific use cases
Providing a fallback in case the redirection or shortening mechanism fails
 
If you have a valid use case to remove it, otherwise it's wise to keep the original url.
 
 

Avatar

Correct answer by
Community Advisor

Hi @nivethaS ,

When you implement URL shortening in AEM, it is common to have the original long URLs still accessible. This is expected behavior as it ensures backward compatibility and avoids breaking existing links. However, for a more seamless user experience and to avoid duplicate content issues (which can affect SEO), it is generally advisable to enforce the shortened URLs and redirect the long ones to their shorter counterparts.

Here’s how you can fully eradicate the /content path and ensure users are only accessing the shortened URLs:

Implementing URL Redirection in AEM

  1. Create a Sling Mapping Configuration: Use the Apache Sling Resource Resolver Factory configuration to create a mapping rule. This will map the long URL to the short URL.

    • Go to AEM Web Console: http://<AEM-HOST>:<PORT>/system/console/configMgr
    • Search for "Apache Sling Resource Resolver Factory".
    • Add the following configuration under the sling:match and sling:redirect properties:

 

{
  "/content/test/en_us/test.html": "/en_us/test.html"
}
​

 

    • This will internally map the long URL to the short URL.
  1. Configure URL Rewriting Using URL Mapping: Create an etc/map configuration in AEM to handle URL mapping.

    • Navigate to CRXDE Lite: http://<AEM-HOST>:<PORT>/crx/de/index.jsp
    • Create the following structure if it doesn’t exist:

 

/etc
  /map
    /http
      /test.com
​
- Under `/test.com`, create a node named `sling:Mapping` with the following properties:
  - `sling:match = "/content/test/(.*)"`
  - `sling:redirect = "/$1"`

 

 

Setup Apache Rewrite Rules: If you are using an Apache HTTP server as a front end to AEM, you can set up rewrite rules to ensure any access to the long URL is redirected to the short URL.

Add the following rewrite rules to your Apache configuration:

 

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/content/test/
RewriteRule ^/content/test/(.*)$ /$1 [R=301,L]

 

  1. This rule will redirect any request that matches /content/test/... to /....

Verification

  1. Testing Redirects: Test the configurations by accessing the original long URL. It should automatically redirect to the shortened URL.

  2. Check Logs and Monitoring: Monitor your AEM logs and web server logs to ensure that the redirections are working as expected and there are no issues.

Notes

  • SEO Considerations: Using 301 (permanent) redirects ensures that search engines understand the move and update their indexes accordingly.
  • Cache Management: If you are using a CDN or caching layer, ensure the cache is purged or updated to reflect these changes.
  • Testing: Perform thorough testing in a staging environment before deploying to production.

By following these steps, you can ensure that users are always directed to the shortened URLs and the original long URLs are properly redirected, thereby eliminating access to the /content path.

Avatar

Community Advisor

@nivethaS Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.