Redirect subdomain to subdomain Apache2

I believe you can solve this by setting up 2 vhosts:

<VirtualHost *:80>
    ServerName inf.xyz.city.eu
    ServerAlias www.inf.xyz.city.eu
    Redirect / http://sth.city.eu/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.sth.city.eu
    ServerAlias sth.city.eu
    ServerAdmin webmaster@localhost      
    [...]
</VirtualHost>

If you have mod_rewrite, you can use RewriteRules:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^inf\.xyz\.city\.eu [NC]
RewriteRule (.*) http://sth.city.eu/$1 [R=301,QSA,L]

What @mikolan was saying is:

in /etc/apache2/sites-enabled/ you should have 2 vhost files:

  1. file: /etc/apache2/sites-enabled/sth.city.eu
<VirtualHost *:80>
    ServerName sth.city.eu
    ServerAlias www.sth.city.eu
    ServerAdmin webmaster@localhost      

    DocumentRoot /var/www/city/

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /var/www/city/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/sth.city.eu.error.log
    CustomLog ${APACHE_LOG_DIR}/sth.city.eu.access.log combined
</VirtualHost>
  1. file: /etc/apache2/sites-enabled/inf.xyz.city.eu
<VirtualHost *:80>
  ServerName inf.xyz.city.eu
  ServerAlias www.inf.xyz.city.eu
  Redirect / http://sth.city.eu/

  LogLevel warn
  ErrorLog ${APACHE_LOG_DIR}/inf.xyz.city.eu.error.log
  CustomLog ${APACHE_LOG_DIR}/inf.xyz.city.eu.access.log combined

</VirtualHost>

Of course, both files are created in /etc/apache2/sites-available, and are enabled with

sudo a2ensite inf.xyz.city.eu
sudo a2ensite sth.city.eu
sudo service apache2 restart
  • Every time you enable/disable site/module a reload is enough, but while testing, restart is more safe (peace mind)

  • Check if the mod_alias is enabled (should be by default)

  • Check the logs to see what errors you get: insufficient permissions, you don't even get the requests?