OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Apache virtual host pointing to intermediary document root

  • Thread starter Thread starter Stefan
  • Start date Start date
S

Stefan

Guest
I have this fodler structure:

Path to my laravel project: /home/name/workspace/myProject

Path to my intermediary indexes: /home/name/workspace/indexes/indexOne /home/name/workspace/indexes/indexTwo

The two folders, indexOne and index Two contain a .env file and public fodler woth a index.php and a .haccess file.

I want my apache2 virtual host to point to one of my intermediary indexes public folder and use the env in that configuration.

If I make my virtual host to point to the /home/name/workspace/myProject/public it works but this is not what I need as that is the normal configuration.

My Virtual host config.

Code:
<VirtualHost *:8002>
        ServerName dev-myApp.be
        ServerAdmin webmaster@localhost
        DocumentRoot /home/name/workspace/indexes/indexOne/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/home/name/workspace/indexes/indexOne/public">
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>

</VirtualHost>

This is my index.php from /home/name/workspace/indexes/indexOne/public:

Code:
<?php
// Redirect to the main index.php file in the project's public folder
$redirectTo = '/home/name/workspace/myProject/public/';

if (strpos($_SERVER['REQUEST_URI'], $redirectTo) === false) {
    header('Location: ' . $redirectTo);
    exit;
}
?>

This is my .htaccess file from /home/name/workspace/indexes/indexOne/public

Code:
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

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

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I get different errors depending on the config I try from 404 to to many redirects to the respoins beeing the content of the index.php file.
<p>I have this fodler structure:</p>
<p>Path to my laravel project:
/home/name/workspace/myProject</p>
<p>Path to my intermediary indexes:
/home/name/workspace/indexes/indexOne
/home/name/workspace/indexes/indexTwo</p>
<p>The two folders, indexOne and index Two contain a .env file and public fodler woth a index.php and a .haccess file.</p>
<p>I want my apache2 virtual host to point to one of my intermediary indexes public folder and use the env in that configuration.</p>
<p>If I make my virtual host to point to the /home/name/workspace/myProject/public it works but this is not what I need as that is the normal configuration.</p>
<p>My Virtual host config.</p>
<pre><code><VirtualHost *:8002>
ServerName dev-myApp.be
ServerAdmin webmaster@localhost
DocumentRoot /home/name/workspace/indexes/indexOne/public

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory "/home/name/workspace/indexes/indexOne/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

</VirtualHost>

</code></pre>
<p>This is my index.php from /home/name/workspace/indexes/indexOne/public:</p>
<pre><code><?php
// Redirect to the main index.php file in the project's public folder
$redirectTo = '/home/name/workspace/myProject/public/';

if (strpos($_SERVER['REQUEST_URI'], $redirectTo) === false) {
header('Location: ' . $redirectTo);
exit;
}
?>
</code></pre>
<p>This is my .htaccess file from /home/name/workspace/indexes/indexOne/public</p>
<pre><code><IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

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

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

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</code></pre>
<p>I get different errors depending on the config I try from 404 to to many redirects to the respoins beeing the content of the index.php file.</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
Mohit Pant
M
Top