Expand my Community achievements bar.

SOLVED

Dispatcher level redirect from www to a non www site

Avatar

Level 5

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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 

View solution in original post

3 Replies

Avatar

Community Advisor

@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"
}
...
}

Avatar

Correct answer by
Community Advisor

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 

Avatar

Community Advisor

@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...