-1

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 info@example.com
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/
</VirtualHost>

But not working.

0

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.

0

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 Feb 10 '17 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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