alyn000r
alyn000r

Reputation: 566

Amazon EC2 - Redirect www.domain.com to http://domain.com

I am new to Amazon EC2 Server, I am facing an issue when I enter www.domain.com my website does not load. When I enter http://domain.com it works fine. I googled and found that this is a canonical issue and I should redirect www.domain.com to http://domain.com. On stack overflow I found this thread and I followed it.

Syntax for 301 redirect of www to non-www using httpd.conf

However my problem did not go away. I added the Virtual Host part as mentioned in my answer to my httpd.conf file.

It now looks like this:

<VirtualHost *:80>



DocumentRoot "/var/www/"
  ServerName rafitapp.com
  ServerAlias rafitapp.com www.rafitapp.com

  <Directory "html/">
      allow from all
      Options +Indexes
  </Directory>

  Options +FollowSymLinks
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www.rafitapp.com [NC]
  RewriteRule (.*) http://rafitapp.com%{REQUEST_URI} [R=301,L]

</VirtualHost>

The folder in which my index.html file exists is /var/www/html/.

Please suggest what am I doing wrong. I have googled it for hours and could not fix it.

Any advise would help me a lot.

Thank You

Upvotes: 0

Views: 197

Answers (1)

Roger Creasy
Roger Creasy

Reputation: 1529

You likely need to set your CNAME record in DNS. Also, be sure to clear your browser cache when you test.

Upvotes: 2

Related Questions