Expand my Community achievements bar.

AEM redirect rule for Dam path

Avatar

Level 2

Hi Team,

 

We received a customer request on below requirement, 

 

If we hit the domain (eg: abc.com) it should redirected to particular dam page /content/dam/demo.pdf

 

It will be helpful, if someone could provide me the exact rewrite rule for this.

 

Thanks in advance!

3 Replies

Avatar

Level 10

hi @AnushaAt 

you can add this mod_rewrite rewrite rule to your Dispatcher configuration (e.g., in rewrites/rewrite.rules or your virtual host configuration):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ /content/dam/demo.pdf [L,R=301]

Alternative (with PT flag for internal rewriting):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ /content/dam/demo.pdf [PT,L]

Here is the explanation of flags:

FlagPurpose
^/$Matches only the root path (/)
R=301Sends a permanent redirect (301) to the browser
PTPass Through - internally rewrites without sending redirect to browser
LLast rule (stops processing further rules)

Super small example of a virtual host (just for demo purpose):

<VirtualHost *:80>
    ServerName abc.com
    
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^/$ /content/dam/demo.pdf [L,R=301]
</VirtualHost>
 
If you're using AEM as a Cloud Service, consider using the Pipeline-free URL Redirects feature instead:
  1. Create a rewrite map file in DAM at /content/dam/redirectmaps/mysite-redirectmap.txt

  2. Add the mapping:

/ /content/dam/demo.pdf
  • Configure the Apache rewrite rule to use this map (managed via managed-rewrite-maps.yaml)

With this approach, you enable business users to manage redirects without requiring code deployment.

Avatar

Employee Advisor

Hello @AnushaAt ,

 

You don’t need anything complex here. A single rule that maps the bare domain / to /content/dam/demo.pdf is enough.

If your site is fronted by Apache HTTPD (classic Dispatcher setup), add this to your vhost (inside the right <VirtualHost> block and after RewriteEngine On.

# If the request is just the bare domain (root), redirect to the DAM asset
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /content/dam/demo.pdf [R=301,L]

Example for HTTPS-only virtual host:

<VirtualHost *:443>
    ServerName abc.com
    # … SSL and Dispatcher config …

    RewriteEngine On

    # Redirect root to DAM asset
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^$ /content/dam/demo.pdf [R=301,L]

    # …other rules…
</VirtualHost>

 

Avatar

Employee

Hello @AnushaAt 

If this is AEMaaCS, you can also do this at the CDN Level.

The AEM-managed CDN provides a redirection solution at the Edge level thus reducing round trips to the origin.
The Server-side Redirects feature allows you to configure the redirect rules in the AEM project code and deploy using the Config Pipeline.

kind: "CDN"
version: "1"
data:
  redirects:
    rules:
      - name: redirect-root-to-dam
        when:
          reqProperty: path
          equals: "/"
        action:
          type: redirect
          status: 301
          location: /content/dam/demo.pdf


Reference :

https://experienceleague.adobe.com/en/docs/experience-manager-learn/foundation/administration/url-re...

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...