Dispatcher level redirect from www to a non www site | Community
Skip to main content
Nandheswara
Level 4
May 18, 2023
Solved

Dispatcher level redirect from www to a non www site

  • May 18, 2023
  • 3 replies
  • 1964 views

Hi all,

I have issue that is regarding a redirect from www to a non www site (i.e http$://www.domain.com to http$://domain.com). I know this can be done using sling mapping in /etc/map but faster accessing i wants this done at the dispatcher level according to AEM best practices. This is for an AEM as a Cloud Service instance.

Thanks

Nandheswara

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ShaileshBassi

Hi @nandheswara  This can be easily achieved you using the Rewrite Rules that can be written at the path \dispatcher\src\conf.d\rewrites

Samples file can be found at 

Reference for writting rewrite rules - 

You can try this, if this works directly

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

Hope this helps!

Thanks 

3 replies

Jagadeesh_Prakash
Community Advisor
Community Advisor
May 18, 2023

@nandheswara  can you try below code in your dispatcher filter code 

/filter
{
...
/redirect
{
/glob "*"
/type "redirect"
/redirect "https://example.com{URL}"
/redirectCode "301"
/reason "Permanent Redirect"
/globbing "wildcard"
}
...
}

ShaileshBassi
Community Advisor
ShaileshBassiCommunity AdvisorAccepted solution
Community Advisor
May 18, 2023

Hi @nandheswara  This can be easily achieved you using the Rewrite Rules that can be written at the path \dispatcher\src\conf.d\rewrites

Samples file can be found at 

Reference for writting rewrite rules - 

You can try this, if this works directly

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

Hope this helps!

Thanks 

Shashi_Mulugu
Community Advisor
Community Advisor
May 21, 2023

@nandheswara solutions suggested by others should work.. but I would recommend todo this redirect at CDN level instead of dispatcher level.. as always redirects have to be configured as close to edge as possible...