How to allow www.example.com and example.com on EC2 Ubuntu Instance on AWS

How to allow www.example.com and example.com on EC2 Ubuntu Instance on AWS - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How to allow www.example.com and example.com on EC2 Ubuntu Instance on AWS error on your web browser. Problem :


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.example.com is coming up online. However, example.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?


Solution :

It depends how your domain is configured. If it is in /etc/apache2/sites-enabled/000-default or (example.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.example.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.example.com to example.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]

We hope that this article has helped you resolve the redirects, apache2, ubuntu error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=