Curing a Domain's Split Personality

25 April, 2024

Are you stymied by mydomain.com and www. mydomain.com ending up in different places, even though they should not? If your domain is on a server that uses Apache, and if you have access to the Apache directory (typically /etc/apache2), then it could be an easy fix. In the Apache available sites directory (/etc/apache2/sites-available) should be an entry for each domain hosted on the server. It's common to copy and paste an existing one domain as a template for another. Editing the file /etc/apache2/sites-enabled/mydomain.com shows the following:

 

<VirtualHost *:80> ServerName mydomain.com
ServerAlias www.mydomain.com ServerAdmin webmaster@localhost

DocumentRoot /home/ayendesi/public_html/drupal/d6
<Directory /home/mydomain/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny allow from all
</Directory>

ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit, # alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>

It's the serveralias line that is the important one. This line instructs Apache to accept the alias as an alias for the domain name. Without it, the web server could send the user to the server root directory, which on my server would be /var/www. While you are checking settings, it could well be worth ensuring that the DNS settings for the domain contain an A or C record titled www that points to the same location as the domain record.

Login or Register to Comment!