Learn more about ServerAlias in CWP Servers. Our Server Management Support team is here to help you with your questions and concerns.
ServerAlias in CWP Servers | An Introduction
Apache uses a process to decide the appropriate virtual host for incoming requests based on the Host header.
Today, we are going to take a closer look at Apache’s decision-making process, focusing on the ServerName and ServerAlias directives.
Additionally, we will explore a case that involves DNS records, ServerAlias setup, and using Apache’s configuration files to redirect domains.
Understanding Apache’s Virtual Host Selection
When Apache receives a request, it compares the Host header value with the ServerName and ServerAlias directives of each virtual host.
The selection follows the order listed by the `apache2ctl -S` command. If there isn’t a match, Apache serves the first name-based virtual host. Let’s explore how Apache’s decision-making unfolds and what to do if it behaves unexpectedly.
.htaccess Limitations
Before we proceed, we have to note that relying on .htaccess alone is not a solution. For Apache to interpret the .htaccess file, the access must reach the server within the correct path. In fact, if the access is already directed to a directory on the server, the .htaccess file becomes redundant.
Redirecting Domains with ServerAlias
To redirect one domain (A) to another (B) without altering the URL, the ServerAlias setup is handy. Here’s a step-by-step guide:
- To begin with, point the DNS record of domain (A) to the IP address of domain (B).
- Then, add ServerAlias in the server configuration of domain (B).
At this point, we have to edit the server configuration file. We can find the file at `/usr/local/apache/conf.d/vhosts/domain.conf`.
Then, locate the ServerAlias section:
ServerAlias www.domain.com
We have to edit it manually to include the alias domain (A):
ServerAlias www.domain.com domainA.com
Else, we can mention specify multiple aliases:
ServerAlias www.domain.com domainA.com domainB.com
We can also use a wildcard:
ServerAlias *.domain.com
After these changes, we have to restart the Apache service on the server to apply the configurations.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
Today, our Support Engineers introduced us to ServerAlias in CWP Servers.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments