I had a droplet set up running off an IP address and I needed to add a domain to it.
I added say ‘www.foo.com’ using the domain control panel.
My client also wanted ‘foo.com’ to work and I was in a hurry, so I simply added that domain as well.
Now both work fine (there aren’t any redirections).
Reading back over the DNS documentation however, I see that I apparently shouldn’t have done it that way. The correct procedure is to have added the bare domain foo.com and then added the www version as an alias?
What are the advantages to doing it that way? What’s wrong with what I did? Have I set myself up for problems in the future?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
If you don’t setup redirections to non-www to www. OR www. to non-www. So in that case there is possibility that search engine indexed both non-www. and www. URL and it’s create big mashup.
Read below article by matt cutts
SEO advice: url canonicalization
I hope this will help you
For Nignx:
#run this command#
sudo nano /etc/nginx/site-available/example.com
#copy and paste below content#
server {
listen 80;
server_name 123.456.789.10 example.com www.example.com ;
return 301 http://www.example.com$request_uri;
}
Using this you can redirect your example.com to www.example.com
Adding to @hackosphere answer, the site failed to load when I tried duplicating the server name and returning the 301 to itself. Separating them to two directives does the trick.
server {
listen 80;
server_name 123.456.789.10 example.com ;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com ;
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.