Question

Domain incorrectly redirects to another domain (both hosted on droplet)

Posted January 13, 2019 508 views
Apache WordPress DNS Ubuntu 18.04

Hi, I am hosting two sites, site1 and site2, on my droplet. Both domains directed to the appropriate content until I restarted apache.

I believe there is something incorrect with the conf files but I cannot identify the error. Can anyone assist with pointing it out?

site1 conf file:
<VirtualHost *:80>
ServerAdmin admin@site1.com
ServerName site1.com
ServerAlias www.site1.com/
DocumentRoot /var/www/wordpress
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined

<Directory /var/www/wordpress/>
AllowOverride All
</Directory>

RewriteEngine on
RewriteCond %{SERVERNAME} =site1.com [OR]
RewriteCond %{SERVER
NAME} =www.site1.com/ [OR]
RewriteCond %{SERVERNAME} =www.site1.com
RewriteRule ^ https://%{SERVER
NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

site2 conf file:
<VirtualHost *:80>
ServerAdmin admin@site2.com
ServerName site2.com
ServerAlias www.site2.com/
DocumentRoot /var/www/site2.com
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined

<Directory /var/www/site2.com/>
AllowOverride All
</Directory>
</VirtualHost>

DNS settings are:
site1:
A *.site1.com directs to serverIP
A site1.com directs to serverIP
A www.site1.com direts to serverip
NS1
NS2
NS3

site2:
A *.site2.com directs to serverIP
A site2.com directs to serverIP
NS1
NS2
NS3

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

Try removing the trailing slash in both ServerAlias directive and restart Apache.

Regards

  • Thanks. Removed trailing slash in both ServerAlias directives and restarted Apache via systemctl restart apache2.service command.

    No luck. Any other ideas?

    <VirtualHost *:80>
    ServerAdmin admin@site1.com
    ServerName site1.com
    ServerAlias www.site1.com
    DocumentRoot /var/www/wordpress
    ErrorLog ${APACHELOGDIR}/error.log
    CustomLog ${APACHELOGDIR}/access.log combined

    <Directory /var/www/wordpress>
    AllowOverride ALL
    </Directory>

    RewriteEngine on
    RewriteCond %{SERVERNAME} =site1.com [OR]
    RewriteCond %{SERVER
    NAME} =www.site1.com/ [OR]
    RewriteCond %{SERVERNAME} =www.site1.com
    RewriteRule ^ https://%{SERVER
    NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin admin@site2.com
    ServerName site2.com
    ServerAlias www.site2.com
    DocumentRoot /var/www/site2.com
    ErrorLog ${APACHELOGDIR}/error.log
    CustomLog ${APACHELOGDIR}/access.log combined

    <Directory /var/www/site2.com>
    AllowOverride All
    </Directory>
    </VirtualHost>

Submit an Answer