Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KNietzsche's avatar

subdirectories as virtualhost in Centos 7

in /var/www/html/ I have 2 subdirectories system and test each one with a laravel project

I have created 2 conf files

One file /etc/httpd/conf.d/test.conf

<VirtualHost *:80>
  ServerName x.mydomain.com
  Alias /test /var/www/html/test/public
  DocumentRoot /var/www/html/
  <Directory "/var/www/html/test/public">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

and 1 file /etc/httpd/conf.d/system.conf

<VirtualHost *:80>
  ServerName x.mydomain.com
  Alias /system /var/www/html/system/public
  DocumentRoot /var/www/html/
  <Directory "/var/www/html/system/public">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

I can access http://x.mydomain.com/system and all is ok...but not http://x.mydomain.com/test

Here is the .htaccess from /var/www/html/test/public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        #Options -MultiViews
        Options +FollowSymLinks
    </IfModule>

    RewriteEngine On
    RewriteBase /test/

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteRule ^ index.php [L]
    RewriteRule ^(.*)$ index.php/$1 [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

same for system but with RewriteBase /system/

Do you have an idea to help me to find what's wrong and to solve the issue ? What am I doing wrong ? thanks

0 likes
3 replies
RayC's avatar

Your server is calling the system config and only showing you that url.

<VirtualHost *:80>
  ServerName x.mydomain.com
  Alias /system /var/www/html
  DocumentRoot /var/www/html/
  <Directory "/var/www/html">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

You should not try and point a subdomain to two different directories, not really going to work properly.

You should just point the servername to the main html directory this will allow you to use the subdirectories like

http://x.mydomain.com/system/public

http://x.mydomain.com/test/public

Or another suggestion would be to use two different subdomains:

<VirtualHost *:80>
  ServerName x.mydomain.com
  Alias /test /var/www/html/test/public
  DocumentRoot /var/www/html/
  <Directory "/var/www/html/test/public">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName y.mydomain.com
  Alias /system /var/www/html/system/public
  DocumentRoot /var/www/html/
  <Directory "/var/www/html/system/public">
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Personally I would use two separate subdomains to access each.

Hope this helps.

1 like
KNietzsche's avatar

Tx already for your answer.... First part of your answer...I can only see the content of both directories...using /public... but I would like to see the rendering and without the /public extension

Does that mean that we cannot do the same with a VPS we do in local mode ? With my local server on Windows 10 I have multiple directories and can access each one from same root address like localhost/project1 or localhost/project2... Seems curious to me, I will continue to investigate as well, but I agree that your solution with 2 subdomains could be ok. Hope some other people will share their opinion as well.

KNietzsche's avatar

ok...this below is running pretty well, accessing from x.mydomain.com or y.mydomain.com

Alias /system /var/www/html/system/public/
Alias /test/var/www/html/test/public/

<VirtualHost *:80>
   ServerName x.mydomain.com
   DocumentRoot /var/www/html/system/public
  <Directory "/var/www/html/system/public/">
     Require all granted
     AllowOverride all
  </Directory>
</VirtualHost>


Alias /test /var/www/html/test/public/
<VirtualHost *:80>
   ServerName y.mydomain.com
   DocumentRoot /var/www/html/test/public
  <Directory "/var/www/html/test/public/">
     Require all granted
     AllowOverride all
  </Directory>
</VirtualHost>

but I would like to know why I can access for example to x.mydomain.com/phpmyadmin/ or y.mydomain.com/phpmyadmin/ or www.mydomain.com/phpmyadmin/ and not with my laravel projects in directories ....why and/or how to access www.mydomain.com/test www.mydomain.com/system and www.mydomain.com/phpmyadmin

For the moment I will keep @CodebyRay's idea (thks)...but I will continue to work on the topic to try to manage my cases...that should be possible I think, so if you have idea or links...I would appreciate

Please or to participate in this conversation.