Search code examples
.htaccessamazon-web-serviceshttp-redirecturl-rewritingno-www

AWS hosted website not working with non-www. But working fine with www


My domain is with godaddy and files are hosted on aws.

website properly working with www.mydomain.abc, but giving error with mydomain.abc

How can I redirect www.mydomain.abc to mydomain.abc

using these redirect rules in .htaccess

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

Solution

  • Make sure you have an alias to www from the root domain in your zone:

    @ IN A 172.17.2.0
    www IN CNAME @
    

    To confirm this, ping both 'www.example.com' and 'example.com' and confirm they return the same address.

    Update: I corrected the answer per Michael SQL Bot comment below