![Wordpress 多站点子域名解析](https://linux22.com/image/759102/Wordpress%20%E5%A4%9A%E7%AB%99%E7%82%B9%E5%AD%90%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90.png)
我有一个 Wordpress 多站点(我在 AWS 上的 Ubuntu 20.04 服务器上使用 Apache 2.4)。结构是一个主站点(例如 mainsite.com)和三个子域:
aaa.mainsite.com bbb.mainsite.com ccc.mainsite.com
一切正常,除了一个问题:aaa、bbb 和 ccc.mainsite.com 无法解析到各自的主页,而是解析到 mainsite.com 主页。但是,子域下的所有链接都可以正确解析:因此,例如 aaa.mainsite.com/somelink 可以转到正确的位置。
重要提示:此网站已从另一台服务器移出,之前它一直在那里运行。当我添加新的子域名时,它运行正常,但旧子域名仍然无法运行。
我有一个指向 mainsite.com 的 DNS A 记录,以及每个子域的记录,它们都正常工作,解析为我的服务器的 IP。我的 .htaccess 文件如下所示:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
这是 VirtualHost 文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName mainsite.com
ServerAlias *.mainsite.com
DocumentRoot /var/www/mainsite
DirectoryIndex index.php
AddHandler type-map .var
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
# RewriteLog now deprecated
LogLevel debug info warn
<Directory var/www/mainsite>
AllowOverride All
Require all granted
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mainsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mainsite.com/privkey.pem
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mainsite.com
ServerAlias *.mainsite.com
DocumentRoot /var/www/mainsite
DirectoryIndex index.php
AddHandler type-map .var
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
# RewriteLog now deprecated
LogLevel debug info warn
<Directory var/www/mainsite>
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
有人知道我做错了什么吗?