Add Multiple Apache Document Root under one port - apache

I'm looking to have 1 domain point to different drives in my pc.
I've got my document root on D:\ working fine on port 80.
But I also want drive E:\ to show when I load my domain.
I understand I can use virtual hosts on different ports but thats not what I want because I want everything visible under the single domain of the root folder when I load www.example.com.
Is this possible?

No, you cannot have more than one domain root.
You can use mod_alias to configure other file system paths
for example, you could have:
Alias /working d:/working
Alias /other e:/

Related

Multiple Apache Virtual Host Files with one Document root?

I've set up a single VPS running Apache, with an application installed in /var/www/html/. I have a domain [example-1.com] to the server IP.
I'd also like the same application to be served on [example-2.com]. Something similar to creating an 'Alias' domain.
Is it possible to have two Virtual Host Files configured at one document root?
Yes, no problem. The document roots can point wherever you want them to. If the configuration of the second virtualhost is the same, you could also use the ServerAlias directive.

Rewrite with multiple symfony projects under same directory

I'm trying to make some personal projects in my development server, like some sort of intranet.
If I divide each project in a different virtualhost, I set in each computer the host file to each server name and I don't have problems with the rewrite rule and the app.php. But the problem is that I can't modify the host file in an android device so I can't access those webs.
What I have in mind is something like this:
I have three symfony projects under my home folder
/home/user/projects/project1
/home/user/projects/project2
/home/user/projects/project3
Then, under the default folder of apache I make soft links to the web folder to every project:
ln -s /home/user/projects/project1/web /var/www/html/project1
ln -s /home/user/projects/project2/web /var/www/html/project2
ln -s /home/user/projects/project3/web /var/www/html/project3
So I can access them this way:
http://server-ip/project1
http://server-ip/project2
http://server-ip/project3
The problem is that I use those url I need to add the default app.php. I've been trying to modify the .htaccess file of each project, but I don't what to modify. I'm using the default virtualhost configuration and the default .htaccess file of each project.
I think that I need to modify the RewriteCond line, but I don't know what to do.
Thanks
I've got a local development environment (it's actually running on a linux server, under my desk, but the same setup would apply to any other configuration of server).
The webserver has a local IP address, reachable from elsewhere on the local network, including from my phone over WiFi.
All the development sites have their own Vhost configured on the server, with a common DNS prefix - something like *.devserver.domain.com.
The DNS is configured so that devserver.domain.com and the wildcard *.devserver.domain.com return 192.168.1.75 (or whatever the internal, static IP address is). This is a public domain name that has an A record to a local-range IP address, but it's entirely valid.
If you don't have a domain name that you can add wildcard DNSs to, you can use a service such as http://nip.io/ - and so the vhost Servername would be something like:
project1.192.168.1.75.nip.io
project2.192.168.1.75.nip.io
... etc
You may end up regularly editing the apache vhost if you internal IP changes at all, and maybe finding alternate wildcard DNS servers (my go-to was xip.io, but that isn't diffcult to do).
You may also be able to use an internal wildcard for an Apache ServerName/serverAlias: ServerAlias mysite.*.xip.io.

Apache URI path recognition / mapping?

I have a website for all intents and purposes is called.
www.foobar.com
Which in my server path is /var/www/
I tried to create a new folder in /var/ called "analytics", with the hope that if I typed www.foobar.com/analytics I could access that folder.
However that does not work because it is actually looking for /var/www/analytics instead of /var/analytics
So how can I have multiple directories mapped to a URI?
For phpmyadmin I can access www.foobar.com/phpmyadmin with the phpadmin folder is in a completely different directory. So it must be possible.
However I tried googling but could not find any answers so I guess I do not have the right description of what this functionality is on Apache webservers.
Any help would be appreciated.
You have to create virtual directories in Apache.
If you are using Apache2, then can you go to the directories
/etc/apache2/sites-available and /etc/apache2/sites-enabled.
You have probably only the default virtual directory enabled.
You can make a copy of a virtual directory in the map /sites-available.
A virtual directory starts with specifying what the root directory is.
Then can you use the commands a2ensite and a2dissite in order to enable or disable the virtual directories respectively.
After a change in enabled/disabled virtual directories do you need to restart/reload the apache server.
If you use .htaccess file, do not forget to set AllowAccess (in the tag Directory) to at least FileInfo or .htaccess will be ignored.
If you want to make those directories different hosts, then can you make aliases in /etc/hosts.
On my home computer have I aliases for the ip addresses 27.0.0.1 and 27.0.1.1.
That gives me the possibility to have two different sites at the same time.

htaccess multiple domains on one hosting using subdirectories

I've been trying to make the following thing work for hours, with no luck:
I have a vps hosting at digitalocean running ubuntu and xampp, and I have multiple domains pointing to the same ip address.
What I want to do is load files from different subdirectories for different domains.
So when I enter domain1.com into the browser, it loads the files from /htdocs/domain1/, and domain2.com from /htdocs/domain2/.
I've found several examples about this, but all of them had the same problem when I tried accessing subdirectories like this: domain1.com/test, they all redirected me to domain1.com/domain1/test, and I do not want to see the middle part domain1 in the url.
Is it even possible?
I've tried all the answers scattered around the internet searching for "multiple domains on one hosting htaccess", and "htaccess hide middle part of url".
Thank you for reading.
Assuming you're using apache as webserver:
define a VirtualHost for each domain, or host in domain. Give each VirtualHost as ServerName the host- or domain name you want to associate with it.
specify a different DocumentRoot for each VirtualHost. The DocumentRoot is the path to the actual files.
add the hostnames you want te be able to access the web files under to your DNS zone.
When done correctly, you will be able to access the web presence associated with each host- or domain name, without the need to enter any subdirectories in the URL, nor will their names show.

Mapping folder to different folder on the same Apache Server

I have My old domain on my server myexample.com with folder name "myexample" and a have different domain mymaindomain.com, What i am looking is whenever user opens mymaindomain.com/contest it opens the site that is in "myexample" folder and still keep the url in address bar mymaindomain.com/contest/whatever.xxx using htaccess or httpd on apache server.
Put
Alias /contest /public_html/myexample
in the virtual host definition for myexample.com. Note though, that this may cause links in your content to be wrong if they expect to be located at / instead of at /contest.