Mobile app version of vmapp.org
Login or Join
Frith620

: Apache2 subdomain to domain [SSL] 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

@Frith620

Posted in: #Apache2 #Https #Redirects

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 server.example.com they will be redirected to 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 / example.com/ </VirtualHost>


But not working.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Frith620

2 Comments

Sorted by latest first Latest Oldest Best

 

@Reiling115

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

10% popularity Vote Up Vote Down


 

@Alves908

if someone goes to 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 <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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme