0

Here's my vhost file:

UseCanonicalName Off

<VirtualHost *:80>
    VirtualDocumentRoot /Users/username/Sites/%-2+
    ServerName test
    ServerAlias *.test
</VirtualHost>

I use it for my local development. Under directory ~/Sites i have all the site folders, for example: ~/Sites/myblog. This virtualdocument thingy is working well, except for www to non-www redirect. If i type in a browser: www.myblog.test it throws an error "Not found". How can i make it work as www.myblog.test and myblog.test together?

Alexander Kim
  • 597
  • 3
  • 8
  • 21

1 Answers1

0

From the example you gave, you would need:

VirtualDocumentRoot /Users/username/Sites/%-2

Have a look at https://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html, under "Directory Name Interpolation"

-2  the penultimate part

while yours is:

-2+     the penultimate and all preceding parts
Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11