Considering a subdirectory as the root directory for apache

I'm probably going to ask a really stupid question, but I can't find a way to do what I want.

I want to upload a project to my server at http://example.com/MyNewProject

In each of the web pages, I include a file that does all the import for StyleSheets, javascript, etc. I do not want to provide the full path every time I just want to do /MyStylesheet.css

My main roots are the websites /var/www/html/example and my catalog of new projects is stored in /var/www/html/example/MyNewProject .

What I want in my import, when I do /MyStylesheet.css instead of going to the main web directory of my servers, will go to / var / www / html / example / MyNewProject to get CSS.

I tried adding the following to the apache config file:

 Alias /NewProjectTemplate "/var/www/html/example/NewProjectTemplate" Alias /NewPRojectTemplate/ "/var/www/html/example/NewProjectTemplate" <Directory "/var/www/html/example/NewProjectTemplate"> Options Indexes FollowSymLinks Includes AllowOverride All XBitHack On Order allow,deny Allow from all </Directory> 

This, unfortunately, did not work, so I also tried to add the following to the virtualhosts file:

 <VirtualHost *:80> DocumentRoot /var/www/html/example/NewProjectTemplate ServerName example.com/NewProjectTemplate </VirtualHost> 

I looked at Google, but I can’t find anything specific, the only thing I found was to do something using the Rewrite mechanism, but it seems too complex and OTT for my needs.

Thanks for any help you can provide.

UPDATE

Well, I have a little further, although not so much, I am sure it should not be so difficult.

Instead of using virtual hosts, I now use an alias, and below what I added to the httpd.conf file

 DocumentRoot "/var/www/html" Alias /NewTemp/ "/var/www/html/example/NewProjectTemplate/" Alias /NewTemp "/var/www/html/example/NewProjectTemplate" <Directory "/var/www/html/example/NewProjectTemplate/"> Options FollowSymLinks Includes AllowOverride all </Directory> <Directory "/var/www/html/example/NewProjectTemplate"> Options FollowSymLinks Includes AllowOverride all </Directory> 

In my HTML in my SSI, I do the following:

 <!--#include file="includes/imports.html"--> 

As you can see, this is a relative path, and Includes is inside the root of NewProjectTemplate. However, this is a template file, so I want it to always go to the root to find the file, so that it is guaranteed to work no matter how deep it is on its site. For example, if I change the line to below, I get an error error processing directive

<!--#include file="/includes/imports.html"-->

Thus, even if it works without /, but not with a slash, if I do not include the slash for this import to work, the import in the imports.html file works even if they contain a leading slash so it always goes to the root. Below is my HTML import file

 <link rel="stylesheet" type="text/css" href="/StyleSheet.css"> <link rel="stylesheet" type="text/css" href="/navigation/top-nav.css"> <link rel="stylesheet" type="text/css" href="/navigation/side-nav.css"> <script type="text/javascript" src="/scripts/jquery.js"></script> <script type="text/javascript" src="/scripts/menu.js"></script> 

So, just to clarify if the file #include file = includes/imports.html works in the SSI directive and /StyleSheet.css is successfully imported, even if it has a slash. If I add / to the SSI path, it is not imported.

But here he gets weirder.

If I then add another file to a subdirectory, for example. NewProjectTemplate/MySubDirectory , and then add the SSI to the file .. /includes/imports.html, it still does not work. It, as the #include file SSI directive, expects the file to be in the same working directory.

Hope this makes sense

+6
source share
2 answers

So, have you tried this on a virtual host?

 <VirtualHost *:80> ServerAdmin emailaddress@domain.com DocumentRoot "/var/www/html/example/" ServerName example.local ServerAlias example.local <Directory "/var/www/html/example/"> Options All Includes Indexes FollowSymLinks Order allow,deny Allow from all AllowOverride All </Directory> Alias /NewProjectTemplate /var/www/html/example/NewProjectTemplate <Directory "/var/www/html/example/NewProjectTemplate"> Order allow,deny Allow from all </Directory> </VirtualHost> 

Hope this helps this time.

0
source

I just stumbled upon this very old threat. There is no need for a host or alias if you just want sub dir to be treated as root.

The way to do this is to change httpd.conf, there you will find

 <Directory> 

just refresh this line and add

 <Directory "your/server/root/original_path/subpath"> # your options </Directory> 
0
source

Source: https://habr.com/ru/post/974437/


All Articles