: Serve a subdirectory out of a parallel server side directory I have an apache server running with two folders in a subdirectory (/var/www/html/example), a virtual host config in httpd.conf serves
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 example.com ServerAlias example.com/services
DocumentRoot /var/www/html/example/service
</VirtualHost>
<VirtualHost *:80>
ServerName example.com ServerAlias mysite.com 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.
More posts by @Mendez628
1 Comments
Sorted by latest first Latest Oldest Best
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 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.