Expand my Community achievements bar.

SOLVED

how to redirect non WWW to WWW with AEM cloud?

Avatar

Level 9

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.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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 

Avatar

Community Advisor

Hi @TB3dock ,

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

 

Kr,

Sanjay

Avatar

Level 2

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]