Назад | Перейти на главную страницу

Проблемы с отображением www в адресной строке

Я недавно купил VPS и домен. VPS работает под управлением Ubuntu 16.04 с Apache 2.4. Когда я захожу в браузер и набираю http://example.com, индексная страница загружается правильно. То же самое произойдет, если я поставлю www перед доменным именем, но в этом случае www исчезает.

Как мне сделать www вставить в адресную строку и, возможно, перенаправить все non-www Запросы? Это очень важно для меня, так как я купил SSL-сертификат для домена сwww включены.

Я пытался изменить настройки DNS, чтобы добиться этого, но до сих пор все мои попытки с треском провалились.

Мои текущие (рабочие) настройки:

=== A records ===
[empty]     31.14.131.29
localhost   127.0.0.1
webmail     62.149.158.92
webmail     62.149.158.91
www         31.14.131.29

=== AAAA records ===
None

=== CNAME records ===
None

Также я пытался использовать .htaccess, но, видимо, запросы были зациклены.

Я впервые настраиваю VPS и чувствую себя немного растерянным. Не могли бы вы показать мне, как это сделать?

редактировать: 000-default.conf содержимое файла

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.grandegiove.com

    ServerAdmin grandegiovestore@gmail.com
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

редактировать: .htaccess файл содержимого

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^grandegiove.com[nc]
RewriteRule ^(.*)$ http://www.grandegiove.com/$1 [l,r=301,nc]

и по-прежнему www не отображается.