Mobile app version of vmapp.org
Login or Join
Frith620

: How to allow www.domain.com and domain.com on EC2 Ubuntu Instance on AWS I have an EC2 Ubuntu Instance that I have apache2 installed on (along with php, mysql, mycrypt for a Laravel project).

@Frith620

Posted in: #AmazonAws #AmazonEc2 #Apache2 #Redirects #Ubuntu

I have an EC2 Ubuntu Instance that I have apache2 installed on (along with php, mysql, mycrypt for a Laravel project). I have set up the correct nameservers, and domain.com is coming up online. However, domain.com (without ) is not working.

I know I have to change something with the vhost, but I am not sure how to do it with the Debian version of Apache2 on the Ubuntu instance.

What file do I edit to do this, and what edit do I have to make? Thank you for your help.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Frith620

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sent6035632

It depends how your domain is configured. If it is in /etc/apache2/sites-enabled/000-default or (domain.com in same directory) file, then edit that file. Otherwise it will be in /etc/apache2/apache2.conf file.

Find ServerName domain.com directive and add this line below that:

ServerAlias domain.com

This will make alias also work for same domain. For these settings to make effect you will need to restart apache2 by using this command as root:

$ service apache2 restart


I would also suggest placing .htaccess file so it actually redirects domain.com to domain.com instead of displaying both sites under separate domains. This is also useful for SEO. In your docroot place this in .htaccess:

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme