1

I have an apache server running with two folders in a subdirectory (/var/www/html/example), a virtual host config in httpd.conf serves URLs from /var/www/html/example/website and /var/html/example/service

I'd like the /var/html/example/service folder to be the root when navigating to example.com/services/ and I'd like /var/www/html/example/website to be the root when accessed via example.com/

From my httpd.conf file this is what I added (unsurprisingly it doesn't work but for clarities sake):

<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com/services
DocumentRoot /var/www/html/example/service
</VirtualHost>

<VirtualHost *:80>
ServerName www.example.com
ServerAlias mysite.com www.example.com
DocumentRoot /var/www/html/example/website
</VirtualHost>

Is this possible to achieve? I was thinking of using redirects or changing virtualhost to do it if that's even possible. I'm mostly worried about the website conflicting with the services.

The website will be a WordPress site if that affects anything.

1

You need to use the Alias directive from mod_alias. It is designed to serve documents for a path from a different server side directory:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/html/example/website
    Alias "/services" "/var/www/html/example/service"
</VirtualHost>

A few notes on what you had tried:

  • You can only have one virtual host configuration per domain. Your attempt to create two virtual hosts for your single site wasn't going to work.
  • ServerAlias is only for domain names. Putting a path into that isn't going to work.

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.