How to Configura Apache PHP Server With Multiple Sites Relative URL

27-10-2016

In XAMPP, we can run multiple web site at any path which is relative to root path by configuring httpd.conf file.

Example: In this example, we used symfony web application as root application and site1 and site2 as follows:

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld
    DocumentRoot C:/xampp/htdocs/symfony/sample/web
    <Directory C:/xampp/htdocs/symfony/sample/web>
        AllowOverride None
        Order Allow,Deny
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>
    Alias /site2 C:/xampp/htdocs/site1
    <Directory C:/xampp/htdocs/site1>
        Order allow,deny
        allow from all
    </Directory>
</Directory>
Alias /site2 C:/xampp/htdocs/site2
<Directory C:/xampp/htdocs/site2>
    Order allow,deny
    allow from all
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
#     Options FollowSymlinks
# </Directory>

# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory C:/xampp/htdocs/symfony/urunTakipSistemi/web/bundles>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
</Directory>

</VirtualHost>

Paste this configuration at the bottom of the httpd.conf file, then type http://localhost. As you can see, symfony web application is started. Then type http://localhost/site1 and http://localhost/site2, respectively.

Note: The most important parts are Alias /site1 C:/xampp/htdocs/site1 and Alias /site2 C:/xampp/htdocs/site2. To accomplish this, we must use Alias keyword.

© 2019 All rights reserved. Codesenior.COM