how to redirect non WWW to WWW with AEM cloud? | Community
Skip to main content
New Participant
September 25, 2021
Solved

how to redirect non WWW to WWW with AEM cloud?

  • September 25, 2021
  • 3 replies
  • 3067 views

The vhost file only seems to support http (non SSL) traffic.

We want to have:

http://ourdomain.com -> https://www.ourdomain.com

https://ourdomain.com - > https://www.ourdomain.com

https://ourdomain.com/something.html -> https://www.ourdomain.com/something.html.

etc.

 

We would guess something like this would be a start:

 

<VirtualHost *:80>

    ServerName ourdomain.com

    Redirect permanent / http://www.ourdomain.com/

</VirtualHost>

 

<VirtualHost *:80>

    ServerName www.ourdoamain.com

    --- real stuff

 

but what about https?

 

We could also consider using rewrite rules, but should they be to http or https?

e.g.

 

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

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

We are going from non www to www as it gives us more options around CNAMES which are not supported at Apex, and make it harder to use Azure traffic manager to put up holding pages when AEM cloud is down.

 

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 Raja-Karuppsamy

Hi - @tb3dock ,

 

1.Should have proper SSL certificate for WWW domain.

2. Should have separate dns node in /etc/map.publish for www domain.

3. Configure WWW and Non-WWW domains in a single virtual host:

In Virtual host:80 section,

ServerName  www.ourdoamain.com

ServerAlias ourdoamain.com

4. In rewrite section,

RewriteRule ^/$ https://%{SERVER_NAME}/<>.html [R=301,L]  ## landing page of the site - all the requests will be redirected to www domain .

RewriteRule ^/content/path/(.*)$ https://%{SERVER_NAME}/$1 [NE,L,R=301] ## content mask

RewriteRule ^/$ https://%{SERVER_NAME}/$1 [L,R=301]

5. Configure the similar rules in ssl.conf file with virtual host:443 

3 replies

New Participant
March 11, 2022

Hi everyone,

 

We need to do same redirection (non-WWW to WWW) on our cloud environment. But we did content path masking via Apache Sling Resource Resolver Factory configuration. We didn't create any mapping under /etc/map.. path. 

Our prod environment have 2 DNS record. One for www , one for non-www. 

 

https://yoast.com/how-to-remove-www-from-your-url/

This document says you can redirect incoming traffic to www on htaccess file. Could we take similar approach?Add below RewriteRule on dispatcher conf and redirect all incoming url to www counterpart?

 

RewriteCond %{HTTP_HOST} ^companyname.com$
RewriteRule (.*) https://www.companyname.com$1 [R=301]

Sanjay_Bangar
New Participant
September 26, 2021

Hi @tb3dock ,

                     You can do it from etc/mapping  using sling redirect.

 

Kr,

Sanjay

Raja-Karuppsamy
Raja-KaruppsamyAccepted solution
New Participant
September 26, 2021

Hi - @tb3dock ,

 

1.Should have proper SSL certificate for WWW domain.

2. Should have separate dns node in /etc/map.publish for www domain.

3. Configure WWW and Non-WWW domains in a single virtual host:

In Virtual host:80 section,

ServerName  www.ourdoamain.com

ServerAlias ourdoamain.com

4. In rewrite section,

RewriteRule ^/$ https://%{SERVER_NAME}/<>.html [R=301,L]  ## landing page of the site - all the requests will be redirected to www domain .

RewriteRule ^/content/path/(.*)$ https://%{SERVER_NAME}/$1 [NE,L,R=301] ## content mask

RewriteRule ^/$ https://%{SERVER_NAME}/$1 [L,R=301]

5. Configure the similar rules in ssl.conf file with virtual host:443