Expand my Community achievements bar.

SOLVED

Redirection rule from non-www to www

Avatar

Level 2

Hi Team,

 

We received a customer request for redirecting a non-www to www

 

abc.com  (any page) should redirect (301) to www.abc.com

 

Can I have some suggestion for implementing this redirection rule. 

 

Thanks in advance!  

1 Accepted Solution

Avatar

Correct answer by
Employee

Hello @AnushaAt 
If you are using AEMaaCS with OOTB Fastly CDN, you can utilize the Server-side Redirects in the CDN Configuration :
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

Example -

kind: "CDN"
version: "1"
metadata:
  envTypes: ["prod", "dev"]
data:
  redirects:
    rules:
      - name: redirect-non-www-to-www
        when: { reqProperty: host, equals: "abc.com" }
        action:
          type: redirect
          status: 301
          location: https://www.abc.com{{ reqProperty: path }}

or you can handle the redirection at the Dispatcher Level :

RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

View solution in original post

7 Replies

Avatar

Level 5

Hi @AnushaAt ,

You can try adding the following rewrite rules to your dispatcher configuration:

RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

This will redirect abc.com to www.abc.com.

 

Let me know if it works.
Thanks.

 

Avatar

Community Advisor

Hi @AnushaAt 

Which CDN are you using? It will be easier/best practice to implement directly at CDN.

Arun Patidar

AEM LinksLinkedIn

Avatar

Correct answer by
Employee

Hello @AnushaAt 
If you are using AEMaaCS with OOTB Fastly CDN, you can utilize the Server-side Redirects in the CDN Configuration :
https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/con...

Example -

kind: "CDN"
version: "1"
metadata:
  envTypes: ["prod", "dev"]
data:
  redirects:
    rules:
      - name: redirect-non-www-to-www
        when: { reqProperty: host, equals: "abc.com" }
        action:
          type: redirect
          status: 301
          location: https://www.abc.com{{ reqProperty: path }}

or you can handle the redirection at the Dispatcher Level :

RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

Avatar

Community Advisor

Hi @AnushaAt ,

Dispatcher (Apache) Redirect Rule

If you're using AEM Dispatcher (Apache HTTP Server), add the following to your dispatcher/src/conf.d/rewrites/rewrite.rules file:

# Redirect non-www to www (permanent 301)
RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

AEM Cloud (Fastly CDN) Configuration

If you're on AEM as a Cloud Service, use Fastly Redirect Rules via CDN Configuration YAML:

kind: "CDN"
version: "1"
metadata:
  envTypes: ["prod", "stage"]
data:
  redirects:
    rules:
      - name: redirect-non-www-to-www
        when:
          reqProperty: host
          equals: "abc.com"
        action:
          type: redirect
          status: 301
          location: https://www.abc.com{{ reqProperty: path }}

Add this to your CDN Config repository (conf/cdn/redirects.yaml), and deploy via Cloud Manager pipeline.

Regards,
Amit

Avatar

Employee

To implement a redirect from non-www to www (e.g. abc.com → www.abc.com), the industry-standard and most reliable approach in AMS/AEM environments is to use an Apache mod_rewrite rule at the Dispatcher (or web server) layer.

Example Rewrite Rule (Apache)

Add the following to your appropriate rewrite configuration file (commonly included in your vhost definition, e.g., /etc/httpd/conf.d/rewrites/base_rewrite.rules in AMS):

RewriteEngine On

# Redirect ONLY non-www to www for any page, preserving the path and query string
RewriteCond %{HTTP_HOST} ^abc\.com [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
  • If you support both HTTP and HTTPS, ensure you listen on both ports, or adapt the rule to switch protocol as needed.
  • If your setup is behind a load balancer or CDN, you may need to consider whether the SSL termination happens before reaching Dispatcher.

Why do it at Dispatcher?

  • You have full control.
  • Changes can be made and tested by your team without waiting for AMS/CDN updates.
  • Consistent with best practices for maintainability and deployment simplicity.

Alternate or Complementary: DNS or CDN Redirection

Some teams also add redirects at the CDN layer (e.g., CloudFront, Akamai) or, in Azure, use the Application Gateway's redirect features, though this usually requires AMS or platform team involvement for changes and isn’t as self-service as the Dispatcher.


Best Practice:

  • Implement and test at Dispatcher.
  • Set up DNS for both abc.com and www.abc.com to point to your entry layer (CDN/LB/Dispatcher).
  • Ensure firewall/security group rules allow HTTP/HTTPS to the dispatcher.
  • Consider also redirecting HTTP to HTTPS inside the same rewrite ruleset if you want to enforce only secure traffic.

Avatar

Community Advisor

@AnushaAt Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!


Aanchal Sikka

Avatar

Administrator

@AnushaAt Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!



Kautuk Sahni