0

I want to redirect all traffic non-www to www (without using route53). I have already created the CNAME www.

How can I do that without changing the code on the site?

The AWS application load balancer is on top of the infrastructure.

womble
  • 96,255
  • 29
  • 175
  • 230
Kaylas
  • 1
  • 1
  • Point non-www at a different server (or if you can use Route53, an S3 bucket via an ALIAS record) that does the redirection. – ceejayoz Sep 06 '16 at 13:15

1 Answers1

2

This would not be done via DNS or at the load balancer this is achieved at the webserver by issuing a redirect. With apache this is best done on in the .htaccess file in the webroot.

The contents of .htaccess should be as follows:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
techraf
  • 4,243
  • 8
  • 29
  • 44
cormpadre
  • 414
  • 2
  • 6
  • 4
    `.htaccess` is not "best"; it's slower and less secure than making the same configuration change in the server config. – womble Sep 06 '16 at 12:57
  • 2
    Using htaccess is definitely not the right thing to do if you have access to the main server config., – user9517 Sep 06 '16 at 12:58
  • It is a little slower as it's processed at time of requests but why load the rules in the main config? applying this redirect to everything indiscriminately could not be best option.. as for less secure...i don't see any reason to say that, if im missing something please enlighten me.. – cormpadre Sep 07 '16 at 15:36