How do I have www + also go to

April 19, 2014 1.8k views
Hey guys, My google-fu hasn't turned anything up, so I thought I'd ask here. My current site is But if I go to I get a not found error. I already have the www A @ record in my DNS for this domain. I have multiple sites on my droplet, so each one has it's own config file in: `/etc/apache2/sites-available` Below are the contents of my config file (I removed my email address even though it's on my site): ` ServerAdmin ServerName ServerAlias DocumentRoot /var/www/adamyala Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined ` What else do I have to add for this to work?
1 Answer
This is done using .htaccess usually, it's called a 301 redirect.
You either go with non-www to www or the other way around.
So using those terms you can find it on google or other search engines.
Sticking with just one is also good for SEO purposes and can increase your Google Page Rank.

Here's generic .htaccess code for www to non-www

#Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!