1

I got two Laravel projects, set on an Apache server. One of the project has it's own domain, let's say it's mydomain.dev, other one's domain is just vps-address.com/project2.

Now, the problem is, when I enter mydomain.dev, I see project1, as it should be. But when I enter mydomain.dev/project2 I see the other project, but I want to make it inaccessible that way. Also, when I enter vps-address.com/project1 or vps-address.com/project2 I get 500 Internal Error, with an error in error.log saying:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary.

This is my folder structure:

/var/www/html/project1
/var/www/html/project2

This is my /etc/apache2/sites-available/000-default.conf:

DocumentRoot /var/www/html
Alias /project1 /var/www/html/project1/public
Alias /project2 /var/www/html/project2/public

<Directory /var/www/html/project1>
    AllowOverride All
</Directory>

<Directory /var/www/html/project2>
    AllowOverride All
</Directory>

<VirtualHost *:80>
        DocumentRoot /var/www/html/
    ServerName vps-address.com
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/project1/public
    ServerName mydomain.dev

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

</VirtualHost>

<VirtualHost *:80>
        ServerName vps-address.com/project2
        DocumentRoot /var/www/html/project2/public
</VirtualHost>

And my .htaccess in both of the /public folders:

<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 would like to make project2 accessible only by this address: vps-address.com/project2, not mydomain.dev/project2, and the project1 to be accessible only: mydomain.dev.

Is that possible to do with Laravel and Apache2?

1 Answer 1

2

Check this config:

DocumentRoot /var/www/html

<Directory /var/www/html/project1>
    AllowOverride All
</Directory>

<Directory /var/www/html/project2>
    AllowOverride All
</Directory>

<VirtualHost *:80>
    DocumentRoot /var/www/html/
    ServerName vps-address.com
    Alias /project2 /var/www/html/project2/public
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/project1/public
    ServerName mydomain.dev

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

</VirtualHost>

Edit: Also change the .htaccess in the /var/www/html/project2/public to this:

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

    RewriteEngine On
    RewriteBase /project2/

    # 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>
Sign up to request clarification or add additional context in comments.

3 Comments

mydomain.dev now works perfectly and doesn't show the project2. But, when I visit vps-address.com/project2 I still get this error: AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Also you need to check your App Url inside .env file in /var/www/html/project2
Everything works as it should! Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.