У меня есть установка Yii2 Advanced с поддоменами. Мой внешний домен http://xxx.tld, однако www.xxx.tld также работает.Yii2 Advanced на Apache2: перенаправление www на не-www
Я хочу, чтобы все запросы www были перенаправлены на не-www. Я пытался использовать традиционные методы, но он, похоже, не работает.
У меня есть запись для всех моих поддоменов и для @
и www
Вот мой конф файл для xxx.tld:
/apache2/sites-available/xxx.tld.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.example.com
ServerName xxx.xxx
ServerAdmin [email protected]
DocumentRoot /var/www/xxx.xxx/frontend/web
<Directory "/var/www/xxx.xxx/frontend/web/">
# Redirect www to non-www
RewriteEngine on
RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE]
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
AllowOverride All
# ...other settings...
</Directory>
# 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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Спасибо! Будет награждать награду, когда она станет доступной – Dean