0

I have redirected my domain to my server, and successfully configure the main domain like this:

/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>

then i try to configure my subdomain like this:

/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>

i already run a2ensite app.mywordpress.com.conf && service apache2 restart but when i access my subdomain it still redirects me to my main domain

i try to configure my main domain .htaccess like this:

/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>

but still not working

mileven
  • 101
  • 1
  • It is your subdomain which is redirecting, so you need to look at the configuration for the subdomain. The main domain configuration is not relevant right now. Please edit your post and make sure it contains all relevant configuration. – Michael Hampton Aug 31 '18 at 12:12
  • Have you cleared browser cache? You are using permanent redirects and have probably tested the URL before making the changes. – Esa Jokinen Aug 31 '18 at 17:25

0 Answers0