Hide the /content Root Path in AEM Publish and Website URLs

It is good practice to hide the content path from the public domain and from publish server URLs. Here is one of the best approaches.
Say the website is on this public URL:
https://[websitename.com]/content/sitename/fr/home.html
and AEM serves it at:
http://<hostname>:<port>/content/sitename/fr/home.html
The recommended practice is to keep /content/sitename out of the public URL. That takes configuration on both the publish instance and the dispatcher.
Configuration on publish
Configure the Apache Sling Resource Resolver Factory so URLs are rewritten on the publish server. Add these entries under URL Mappings:
/content/sitename/(.*)</$1
/content/sitename/fr$1>/fr(.*)
Save the configuration and open http://<hostname>:<port>/fr/home.html — the home page loads on publish without /content/sitename. After saving, the relevant bundles take a little while to restart.
Configuration on the dispatcher
Publish now answers without the content path. Next, make the public domain behave the same way through the dispatcher.
Step 1. Make sure the mod_rewrite module is loaded in Apache:
#
# This file loads most of the modules included with the Apache HTTP server
#
LoadModule rewrite_module modules/mod_rewrite.so
Step 2. Set DispatcherUseProcessedURL to 1 so the dispatcher uses the processed (rewritten) URLs:
<IfModule disp_apache.c>
# Enabled so that rewrites take effect
DispatcherUseProcessedURL 1
</IfModule>
Step 3. Add these rules to the virtual host file (usually under conf.d):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/$ $1
# Shorten the URL
RewriteRule ^/content/sitename/(.*).html$ $1.html [R,L]
# Redirect the root to the fr home page
RewriteRule ^/?$ fr/home.html [R,L]
</IfModule>
Restart Apache and open https://[websitename.com]/fr/home.html — the home page loads without the content path.
The same resource resolver mapping technique serves a robots.txt from the DAM.
More in Operations, SEO and upgrades
- Robots.txt File in AEM Websites
How to serve a robots.txt from an AEM website: store it in the DAM, map it to /robots.txt with the Sling resource resolver, and allow it through the dispatcher.
- What Is the AEM Pattern Detector? Its Role in Upgrading to AEM 6.4
How the AEM Pattern Detector scans a code base before an upgrade, what its report codes (OCU, ECU, LOCP, NBCC, CAV) mean, and where to run it.
- Steps to Migrate a Third-Party CMS Website to AEM
The steps of a CMS-to-AEM migration project: analysis, content and asset strategy, design, content migration (manual, automated, hybrid), testing and estimation.
- Generate a Report of Users' Last Login in AEM
How to report every user's last login in AEM 6.5: record it with an AuthenticationInfoPostProcessor service, then query it with an ACS AEM Commons report.
- ACS AEM Commons Page Compare Utility in AEM 6.4
What ACS AEM Commons adds to AEM, how to install it, and how to use its Page Compare tool to compare the content and structure of two pages.