D
D
Discout2015-04-24 13:55:55
Apache HTTP Server
Discout, 2015-04-24 13:55:55

Digitalocean: how to redirect to www?

I created a wordpess blog on digitalocean, I realized that it doesn’t go to the page if it says www.myname.ru. Comes only without www. I added www to the url in the wordpress admin panel and now I can't access the site at all.
How to fix it? And how to make the site work on the link with and without www?
Server: apache
OS: ubuntu.
Please explain step by step. I don't understand this topic. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-04-24
@Discout

You need to find the config of your virtual host in /etc/apache2/ (usually in /etc/apache2/site-availiable/) and add an alias in it:

ServerName  site.ru
ServerAlias site.ru *.site.ru

In general, it is better to have one host for SEO, mirrors are not needed. Therefore, create a .htaccess file in the root and write a redirect to the site without www in it:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site.ru$ [NC]
RewriteRule ^(.*)$ http://site.ru/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question