Hi @helptech ,
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
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.
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]
This rule will redirect any request that matches /content/test/... to /....
Verification
Testing Redirects: Test the configurations by accessing the original long URL. It should automatically redirect to the shortened URL.
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.