Reputation: 107
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?
Upvotes: 1
Views: 1175
Reputation: 379
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>
Upvotes: 2