Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 www.domain.com is coming up online. However, domain.com (without www.) 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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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 www.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 www.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 ^(.*)$ http://%1/$1 [R=301,L]
share|improve this answer
    
Ok, the only file I'm seeing in /etc/apache2/sites-enabled is 000-default.conf. And I'm not seeing a conf directory in /etc/apache2/ . I am only seeing conf-available and conf-enabled. I found apache2.conf file in the /etc/apache2 directory, but it does not have a line "SeverName domain.com". Any ideas? –  user1072337 Mar 23 at 20:22
    
check 000-default.conf file. If that one does not have configuration for domain.com then it will be /etc/apache2/apache2.conf –  edvinas.me Mar 23 at 20:31
    
There's this commented out in that file: #ServerName www.example.com Should I uncomment this? And then add another line ServerName example.com –  user1072337 Mar 23 at 20:33
    
I added: ServerName www.domain.com ServerAlias domain.com –  user1072337 Mar 23 at 22:29
    
And it is still not working for domain.com –  user1072337 Mar 23 at 22:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.