子域名始终重定向到主域名

子域名始终重定向到主域名

我已将我的域名重定向到我的服务器,并成功配置主域名,如下所示:

/etc/apache2/sites-available/mywordpress.com.conf

 <VirtualHost *:80>

    ServerName www.mywordpress.com
    ServerAlias mywordpress.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mywordpress.com/public_html

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

    RewriteEngine off
    RewriteCond %{SERVER_NAME} =mywordpress.com [OR]
    RewriteCond %{SERVER_NAME} =www.mywordpress.com [OR]
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    <Directory /var/www/mywordpress.com/public_html>
            AllowOverride All
    </Directory>
 </VirtualHost>

然后我尝试像这样配置我的子域名:

/etc/apache2/sites-available/app.mywordpress.com.conf

<VirtualHost *:80> 
        ServerName app.mywordpress.com
        ServerAlias www.app.mywordpress.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/app.mywordpress.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我已经运行了,a2ensite app.mywordpress.com.conf && service apache2 restart但是当我访问我的子域名时,它仍然会将我重定向到我的主域名

我尝试像这样配置我的主域 .htaccess:

/var/www/mywordpress.com/public_html/.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

<IfModule mod_rewrite.c>
RewriteEngine on

# redirect to https www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(mywordpress\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.app.mywordpress\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>

但仍然不起作用

相关内容