Search code examples
wordpressamazon-web-servicesdnsamazon-elbno-www

WP Non-www to www rewrite/redirection on AWS ELB


I was told by my IT department looking after AWS that it is not possible to redirect non-www to www domain name because of the AWS load balanced environment - and that it is not single IP

I am running a wordpress site and I have tried this in the lb .htaccess files with no luck.

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

Just wanting to know if there is another way or is it definitely not possible? thanks


Solution

  • In DNS Hosted Zone Create one CNAME record with www which should point to your ELB domain .

    Edit your .htaccess file with this configuration

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

    Clear cache of your browser and try to access on www domain .