Thomas Portelange
LeKoala Dev Blog

Follow

LeKoala Dev Blog

Follow
Apache mass virtual hosts and lower case letters

Apache mass virtual hosts and lower case letters

Thomas Portelange's photo
Thomas Portelange
·Feb 15, 2022·

2 min read

Just in case you thought having a path starting with c:/ or C:/ was the same... let me tell you how wrong you are.

Setting up my new computer

I've been migrating all my local websites to a new computer, with a fresh install of WAMPServer (yes, I'm not a big docker & co fan). I used to configure my website with a nice little snippet to automatically create all my vhosts like this:

#
# Dynamic Virtual Host Definitions
#
<IfModule mod_vhost_alias.c>
    # example.com              -->  /var/www/vhosts/example.com/www
    # www.example.com          -->  /var/www/vhosts/example.com/www
    # a.www.example.com        -->  /var/www/vhosts/example.com/a.www
    # shop.example.com        -->  /var/www/vhosts/example.com/shop
    <VirtualHost *:80>
      ServerName sub.domain
      ServerAlias *.*.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/%-3"
    </VirtualHost>
    <VirtualHost *:80>
      ServerName bare.domain
      ServerAlias *.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/www"
    </VirtualHost>
    <VirtualHost *:80>
      ServerName sub.domain
      ServerAlias *.*.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/%-3"
      SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.crt"
      SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.key"
      SSLEngine on
    </VirtualHost>
    <VirtualHost *:80>
      ServerName bare.domain
      ServerAlias *.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/www"
      SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.crt"
      SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.key"
      SSLEngine on
    </VirtualHost>
    <VirtualHost *:8000>
      ServerName sub.domain
      ServerAlias *.*.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/%-3/public"
    </VirtualHost>
    <VirtualHost *:8000>
      ServerName sub.domain
      ServerAlias *.*.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/%-3/public"
      SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.crt"
      SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.key"
      SSLEngine on
    </VirtualHost>
    <VirtualHost *:8000>
      ServerName bare.domain
      ServerAlias *.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/www/public"
    </VirtualHost>
    <VirtualHost *:8000>
      ServerName bare.domain
      ServerAlias *.*
      VirtualDocumentRoot "D:/www/%-2.0.%-1.0/www/public"
      SSLCertificateFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.crt"
      SSLCertificateKeyFile "D:/wamp64/bin/apache/apache2.4.51/conf/key/localhost/server.key"
      SSLEngine on
    </VirtualHost>
</IfModule>

This allows me to map mywebsite.local to D:/www/mywebsite.local/ (and to the "public" folder if I'm using port 8000). This worked quite well, until my recent migration.

Seems working, but mod rewrite fails

In the snippet above, I was using a lowercase "d" instead. All the websites work, but as soon as you get a mod rewrite rule, you get an infinite loop resulting in an error 500. I scratched my head for a while, tried an older version of apache... nothing worked.

Until... I tried to rename the lowercase "d:/" to a "D:/"... and it worked! Why? I don't know ! Probably some odd bug that take case into account when interpreting mod rewrite rules.

 
Share this