I have domain with SSL and 4 subdomains like: ftp.example.com, server.example.com etc. I'm trying to redirect from subdomain to domain. Example: if someone goes to https://server.example.com they will be redirected to https://example.com. My apache2 config looks like that:

<VirtualHost *:80>

ServerAdmin [email protected]
DocumentRoot /home/www/public

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

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

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
    # Redirect Requests to SSL
    Redirect permanent / https://example.com/

But not working.

2 Answers 2


if someone goes to https://server.example.com they will be redirected ....

The virtual host you posted is for port 80 (ie. HTTP) so this is never going to redirect https://<anything>. As the comment in the code suggests, "Redirect Requests to SSL" (from HTTP).

Exactly how you implement this depends on how the subdomains are implemented... are they separate virtual hosts or ServerAlias, etc.?

Depending on the implementation then the redirect you give should work if you have separate virtual hosts. However, if you have a single virtual host container then you may need to use mod_rewrite and check the host which is being accessed. But whether this works at all may be dependent on the type of SSL cert you have implemented.


Instead of a virtual host configuration, you can just create an CNAME record in your DNS for the subdomain to point to the main domain

  • This doesn't answer the question. The OP already has "4 subdomains" (however they are implemented) but they wish to canonicalize these by redirecting. The implementation of the redirect is the problem. They might well have a CNAME record already, but this does not "redirect" and a CNAME record by itself is not necessarily sufficient anyway to implement a subdomain.
    – MrWhite
    Commented Feb 10, 2017 at 17:18
  • A CNAME only points a domain to the same server as some other domain. You still need server configuration (virtual hosts) so that the server knows what to serve when it receives requests for that domain. Usually you don't want to serve the same content as the main domain. You either want different content, or you want to redirect to the main domain. Commented Aug 10, 2022 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.