4

Wise people,

I am trying to accomplish the following:

Redirect these:

http://www.veluwsvuurbarneveld.nl    
http://veluwsvuurbarneveld.nl 
https://www.veluwsvuurbarneveld.nl

To

https://veluwsvuurbarneveld.nl

Goal is to send all related URL's to the non-www, SSL address.

This is the code in mij apache2 config (Lines that point to SSL keys removed):

<VirtualHost *:443>
     ServerName veluwsvuurbarneveld.nl
     DocumentRoot /var/www/

     SSLEngine on
     SSLCertificateFile /etc/ssl/certs/...
     SSLCertificateKeyFile /etc/ssl/private/...
     SSLCACertificateFile /etc/ssl/certs/...
</VirtualHost>
<VirtualHost *:80>
     ServerName www.veluwsvuurbarneveld.nl
     Redirect permanent / https://veluwsvuurbarneveld.nl/
</VirtualHost>
<VirtualHost *:80>
     ServerName veluwsvuurbarneveld.nl
     Redirect permanent / https://veluwsvuurbarneveld.nl/
</VirtualHost>
<VirtualHost *:443>
     ServerName www.veluwsvuurbarneveld.nl
     Redirect permanent / https://veluwsvuurbarneveld.nl/
</VirtualHost>

<Directory /var/www/>
    Options +ExecCGI
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
</Directory>

The result is that http://veluwsvuurbarneveld.nl is rerouted correctly, but the two www. URL's are not. My first thought was that the https://www. also needed a certificate. This however does not explain the other www. not working.

My .htaccess looks like this (generated by wordpress):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Output from apache2ctl -S:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server localhost (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost www.veluwsvuurbarneveld.nl (/etc/apache2/sites-enabled/veluwsvuurbarneveld.nl.conf:10)
         port 80 namevhost veluwsvuurbarneveld.nl (/etc/apache2/sites-enabled/veluwsvuurbarneveld.nl.conf:14)
*:443                  is a NameVirtualHost
         default server veluwsvuurbarneveld.nl (/etc/apache2/sites-enabled/veluwsvuurbarneveld.nl.conf:1)
         port 443 namevhost veluwsvuurbarneveld.nl (/etc/apache2/sites-enabled/veluwsvuurbarneveld.nl.conf:1)
         port 443 namevhost www.veluwsvuurbarneveld.nl (/etc/apache2/sites-enabled/veluwsvuurbarneveld.nl.conf:18)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Note that I want to solve this problem using the apache2 config file, not via mod_rewrite (httpd.apache.org/docs/trunk/rewrite/avoid.html)

Any ideas?

2 Answers 2

4

This should work:

<VirtualHost *:80>
     ServerName veluwsvuurbarneveld.nl
     ServerAlias www.veluwsvuurbarneveld.nl
     Redirect permanent / https://veluwsvuurbarneveld.nl/
</VirtualHost>
<VirtualHost *:443>
     ServerName www.veluwsvuurbarneveld.nl

     SSLEngine on
     SSLCertificateFile /etc/ssl/certs/...
     SSLCertificateKeyFile /etc/ssl/private/...
     SSLCACertificateFile /etc/ssl/certs/...

     Redirect permanent / https://veluwsvuurbarneveld.nl/
</VirtualHost>
<VirtualHost *:443>
     ServerName veluwsvuurbarneveld.nl
     DocumentRoot /var/www/

     SSLEngine on
     SSLCertificateFile /etc/ssl/certs/...
     SSLCertificateKeyFile /etc/ssl/private/...
     SSLCACertificateFile /etc/ssl/certs/...
</VirtualHost>

<Directory /var/www/>
    Options +ExecCGI
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
</Directory>
2
  • ` but then you will need two distinct IP addresses for your SSL vhosts.` ...kinda, most browsers support SSI nowadays so it's less of an issue, but it could possibly cause problems.
    – Nathan C
    May 2, 2016 at 17:38
  • Thanks for pointing that out, I removed my edit. The above definitely works, I just tested it, although I think at first I had some caching issues (server not found), but a manual DNS lookup worked, after that it worked also in the browser.
    – rda
    May 2, 2016 at 18:16
0

Thank you for answering my question. After using your (RDA's) code for the apache2 config file, the problem persisted. It turns out your code is completely correct but the problem was with my DNS records.

I forgot to add DNS records to the www. domains with my provider (Digital Ocean). For the above code to work, both www and non-www requests first need to be directed to my server. After adding the DNS records for www.veluwsvuurbarneveld.nl the problem was solved.

My mistake!

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .