By joseph762962
I have successfully followed the tutorial: How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS.
I can access mysite.co.uk and also www.mysite.co.uk
However, I would like to show www.mysite.co.uk when I type in mysite.co.uk
I have tried a 301 direct in the virtual host file but that didn’t work, neither did creating a an .htaccess file and using the following code:
RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [nocase] RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301]
Edit: I have already amended the apache2.conf to AllowOverride All and created an .htaccess file in the root of the site directory.
Thank you for any assistance.
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!
That way I would do it is creating a new VirtualHost for mysite.co.uk and having it redirect to www.mysite.co.uk:
<VirtualHost *:80>
ServerName mysite.co.uk
Redirect 301 / http://www.mysite.co.uk
</VirtualHost>
Make sure you remove any instances of mysite.co.uk in your current VirtualHost (ServerName and ServerAlias) and restart Apache:
sudo service apache2 restart
I had the same problem. Then I figure it out and wrote a content regarding this issue. If you want the best and easiest way then visit http://www.techuworld.com/non-www-to-www-or-www-to-non-www-digitalocean/ you will find the answer both for non-www to www and www to non-www
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.