How to create redirection from two domains in one VirtualHost directive in Apache?

Posted on

How to create redirection from two domains in one VirtualHost directive in Apache? – Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again. Below are some tips in manage your apache2 server when you find problem about apache-2.2, virtualhost, httpd.conf, , .

I want users visiting either of napiwki.kontestacja.com and napiwek.kontestacja.com to be redirected to the same address. I’m using the following fragment in httpd.conf:

<VirtualHost *>
ServerName napiwki.kontestacja.com
RewriteEngine on
RewriteRule .* https://tipanddonation.com/Kontestacja
</VirtualHost>
<VirtualHost *>
ServerName napiwek.kontestacja.com
RewriteEngine on
RewriteRule .* https://tipanddonation.com/Kontestacja
</VirtualHost>

I’ve tried different possibilities which should work according to my reading of the documentation but don’t – it always causes just napiwki to redirect and napiwek to result in HTTP 403. Namely, I put these in a single VirtualHost directive:

ServerName napiwki.kontestacja.com
ServerAlias napiwek.kontestacja.com

or

ServerAlias napiwki.kontestacja.com napiwek.kontestacja.com

or

ServerAlias napiwek.kontestacja.com napiwki.kontestacja.com

I’m running Server version: Apache/2.2.15 (Unix). Could you explain to me why the above configurations don’t work as expected?

# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    is a NameVirtualHost
         default server stopacta2.org (/etc/httpd/conf/httpd.conf:1023)
         port * namevhost stopacta2.org (/etc/httpd/conf/httpd.conf:1023)
                 alias www.stopacta2.org
                 alias mail.stopacta2.org
                 alias webmail.stopacta2.org
                 alias admin.stopacta2.org
         port * namevhost kontestacja.com (/etc/httpd/conf/httpd.conf:1063)
                 alias www.kontestacja.com
                 alias mail.kontestacja.com
                 alias webmail.kontestacja.com
                 alias admin.kontestacja.com
         port * namevhost czat.kontestacja.com (/etc/httpd/conf/httpd.conf:1103)
         port * namevhost napiwki.kontestacja.com (/etc/httpd/conf/httpd.conf:1118)
         port * namevhost napiwek.kontestacja.com (/etc/httpd/conf/httpd.conf:1123)
         port * namevhost discord.kontestacja.com (/etc/httpd/conf/httpd.conf:1128)
         port * namevhost kontestgra.pl (/etc/httpd/conf/httpd.conf:1133)
         port * namevhost gra.kontestacja.com (/etc/httpd/conf/httpd.conf:1139)
         port * namevhost nowa.kontestacja.com (/etc/httpd/conf/httpd.conf:1145)
         port * namevhost www.kontestacja.com (/etc/httpd/conf/httpd.conf:1150)
                 wild alias *.kontestacja.net
         port * namevhost zus.kontestacja.com (/etc/httpd/conf/httpd.conf:1156)
Syntax OK

<VirtualHost *>
  ServerName napiwki.kontestacja.com
  ServerAlias napiwek.kontestacja.com
  ...
</VirtualHost>

(or the other way around) is the right configuration.

I see that both napiwki.kontestacja.com and napiwek.kontestacja.com have the same set of several IP addresses. Are you sure that all of those are being answered by this configuration?

Leave a Reply

Your email address will not be published.