2

I'm having problems to rewrite the canonical URL with www to non-www in my domain. If I try www.example.com and I allways get #404. Here is all the information about the apache2 configuration.

This is all what I have checked:

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
        ServerAdmin info@example.com
        ServerName example.com
        DocumentRoot /var/www/example.com
        <Directory /var/www/example.com>
                AllowOverride All
         <IfModule mod_rewrite.c>
                 Options +FollowSymLinks
   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^www.example.com [NC]
   RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
         </IfModule>
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
 
</VirtualHost>
/etc/apache2/apache2.conf

.
.
.
<Directory />
 Options FollowSymLinks
 AllowOverride All
 Require all denied
</Directory>

<Directory /usr/share>
 AllowOverride None
 Require all granted
</Directory>

<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
</Directory>
.
.
.

and the last information phpinfo() enter image description here

Any idea? Thanks!

Erusso87
  • 667
  • 1
  • 7
  • 19
  • 1
    Are you sure that the problem is what you suppose it is? After all, you might have some source-code working with the url as well. So, I guess you should check both htaccess and your source-code for potential problems. Also, take a look at the rewrite rules. – Lajos Arpad Jul 31 '15 at 14:07
  • BTW Allowoverride has no bearing on your config rewrite rules here because you are **not** using .htaccess but using rewrite in the config. So to prevent unnecessary performance hit, turn it off. `AllowOverride None`. Also did you restart apache after the config change? – Panama Jack Jul 31 '15 at 14:33
  • I've tried with .htaccess and I restarted apache after every change. – Erusso87 Jul 31 '15 at 15:03

1 Answers1

0

[SOLVED]

I just added the alias clause in the virtual host definition and created and CNAME record www.example.com in the DNS zone.

ServerName example.com
ServerAlias www.example.com
Erusso87
  • 667
  • 1
  • 7
  • 19