Question

vhost is redirecting to another subdomain.

Hello Everyone,

I have a confusing issue configuring vhost in apache on Ubuntu 18.04.

I have this wordpress vhost config:

<VirtualHost *:80>
    ServerAdmin mail@outlook.com
    ServerName blog.mydomain.com
    ServerAlias www.blog.mydomain.com
    DocumentRoot /var/www/blog
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/blog/>
    AllowOverride All
</Directory>

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.blog.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =blog.mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

And then, I have a PHP app in another directory, the vhost config file is:

<VirtualHost *:80>
    ServerAdmin mail@outlook.com
    ServerName subdomain.mydomain.com
    ServerAlias www.subdomain.mydomain.com
    DocumentRoot /var/www/subdomain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/subdomain/>
    AllowOverride All
</Directory>
</VirtualHost>

I Configured the DNS records. but subdomain.mydomain.com is redirecting me to blog.mydomain.com.

Is there a missconfiguration or something else? (I’m really noob on apache configurations, sorry if it’s stupid.)

Greetings, and stay safe!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hello, @preshu

Have you tried to temporary remove or comment out the Rewrite rules in the first virtual host if they’re not needed?

RewriteCond %{SERVER_NAME} =www.blog.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =blog.mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Also are you using .htaccess files as well and if so can you share the content of both .htaccess files so we can check them?

Let me know how it goes.

Regards, Alex