Redirect to a subfolder in Apache virtual host file - apache

I have Joomla installed on a webserver running Ubuntu Server 12.04. The Joomla folder is located at /var/www/cms/.
My vhost file at /etc/apache2/sites-enabled/default has the following content:
<VirtualHost *:80>
ServerName domain.com/
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName domain.com:443
DocumentRoot /var/www/cms
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/cms>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
(...)
</VirtualHost>
At the moment, all the requests to domain.com and anything entered after that like domain.com/example gets directed and processed by Joomla which either redirects to a proper page or returns a custom 404 error. This all works.
Now, I would like to filter all the requests that go to domain.com/subfolder before they get processed by Joomla and redirect them to /var/www/subfolder (instead of my root folder at /var/www/cms/).
I believe the file in /etc/apache2/sites-enabled/default (seen above) is the right place to define such a redirect, however I have not been able to figure out at what position and how to achieve this.

You should add to your configuration:
Alias /subfolder /var/www/subfolder
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
and fit the configuration between "Directory" to your needs.
See the Apache documentation to have more informations.

Related

Make all subdomains point to on single file/folder using ".conf" file

I wanted to redirect all my subdomain to a single file/folder I done the pointing thing before using .conf files in apache but I did it for a specific domain.
this is the conf file that I use for pointing the domain.
listen 80
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
but what I want is to redirect all the subdomain to redirect to the same project which has some domain for example:-
currently, the upper conf file will redirect to my project folder but what I want is that if I have domain-like
sd1.domain.com
sd2.domain.com
sd3.domain.com
they should also point to the same project directory. but I am not sure how to do it
thx in advance
I solved my problem by doing a slight change into my .conf file here is my new file
listen 80
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
what I did I add the server alias to (*) which let me allow to redirect all my subdomain to single project.

Virtual host not displaying correct files

Centos 7.1 and apache 2.4 - We have installed a new drive in our server and want to move all of our sites to that drive (mounted as /data) and sites are located in /data/vhosts
When trying to access the site we are presented with the apache welcome screen. I can confirm that the vhost is loaded as trying changing the permissions of the dir above results in a forbidden access. There is also an index.php file located in /data/vhosts/test.mydomain.com/public_html
# IP has been changed for example:
<VirtualHost 91.91.91.91:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory /data/vhosts/test.mydomain.com>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>
UPDATE 1:
I have deleted the welcome.conf file in /etc/httpd/conf.d/ and I am not given a forbidden 403. It is important to note that this is a new drive and no permissions has been set on /data (or sub folders) for apache. I am not entirely sure if that makes a difference?
I have also made some slight alternations to the vhost conf file but no difference:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory "/data/vhosts/test.mydomain.com">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory /data/vhosts/test.mydomain.com/public_html>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

How I can setup main directory instead web directory to my website in Symfony?

Actually I make a clone of a previous site that I have on symfony. I copy all directory and files on a same server and assign other domain. I can not access to this clone thru the www.domain.com. To view my site I need to do this: wwww.domain.com/proyect/web/app.php.
My question is: What I need to do to load my site on principal directory?.
Change Your config of the webpage, e.g.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/proyect/web/
<Directory /var/www/proyect/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and restart apache

Two sites with Apache virtual hosts

I'm working on 2 different sites. I have local copies of them checked out from SVN at my home folder, and symbolic links in /var/www pointing to them.
I've set up virtual hosts in httpd.conf like this:
<VirtualHost *:80>
DocumentRoot /var/www/siteA
ServerName 192.168.0.10/siteA
<Directory "/var/www/siteA">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/siteB
ServerName 192.168.0.10/siteB
<Directory "/var/www/siteB">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to be able to access the sites with 192.168.0.10/siteA and /siteB, but when typing the address in browser, it throws a 404 and apache error log says: "File does not exist: /var/www/siteA/siteA".
What am I doing wrong and where does the second "/siteA" come from?
You've got too much configuration in there. /SiteA and /SiteB should be paths relative to your site root, you can't have different sites on the same host header, which in this case is "192.168.0.10". If you want to bind that address to the configuration, something along the lines of the following should work.
<VirtualHost 192.168.0.10:80>
DocumentRoot /var/www
ServerName 192.168.0.10
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you now browse to /SiteA, /SiteB you should see the contents of your directory as long as your symlinks are correct. You also need to ensure you have the "NameVirtualHost" directive set correctly in your httpd.conf.

apache virtual host not opening when given subfolders

I have set up a virtual host in apache this morning and it works well for the root folder.
Settings for virtual hosts -
<VirtualHost *:80>
ServerName dev.abcworld.com
ServerAlias dev.abcworld.com
DocumentRoot C:\nem\wamp\www\dev\html
<Directory C:\nem\wamp\www\dev\html>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName prod.abcworld.com
ServerAlias prod.abcworld.com
DocumentRoot C:\nem\wamp\www\prod\html
<Directory C:\nem\wamp\www\prod\html>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Example :
dev.abcworld.com - works well
prod.abcworld.com - works well
but when ever I click a link in dev.abcworld.com which is supposed to redirect to another page in the project like dev.abcworld.com/payments or dev.abcworld.com/somthing or dev.abcworld.com/anything it always says "The requested URL /apartments was not found on this server."
why does is works only on the root folder? how can i make this work for the whole project both in dev and prod?
open your browser console and check to which path it is sending request.