My web returns a 403 on www.example.com, but works ok on [name].com. In my apache2.conf file, I have ServerName=www.example.com, as well as in the VirtualHost tag, but there I have ServerAlias=example.com as well:

<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com

When I run /usr/sbin/apache2ctl -S, I get:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/www.example.com.conf:1)
                 alias example.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

What I want is for www.example.com and example.com to point to the same service. Now it seems that it's using the default conf file when the www prefix is used.

  • Can you post your virtual host file instead ? Thanks (:
    – Eric Ly
    Apr 16 '15 at 8:30
  • I "solved" this by setting ServerName haha.com in the main apache2.conf file. Would have liked to fix it properly, though... Apr 16 '15 at 8:53
  • Set the ServerName as a default name like localhost so it does not interfere with your virtual host www.[name].com.
    – Eric Ly
    Apr 16 '15 at 8:56
  • Btw, it should be ServerName domain.tld; ServerAlias sub.domain.tld, try to dissite your default conf and set a proper one for your service. Apr 16 '15 at 9:07

Just in case someone is looking for the answer, using the comments under the question, I set the ServerName in /etc/apache2/apache2.conf to localhost.

That, coupled with a correct VirtualHost and htaccess redirect, every "version" of my domain goes to the same one.

Thanks to erikwkolstad and DeadEye for the pointers.

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.