I am having problems getting my .htaccess file to route requests correctly for my Laravel and Angular app.
api
# Laravel api here
public/
...
public_html/
.htaccess
admin/
index.html
front/
index.html
I need some help getting setup with a proper .htaccess to route based on the three domain calls I am making:
api.domain.com > routes to /api/public
admin.domain.com > routes to /admin/index.html
domain.com > routes to /front/index.html
Can anyone help me with this please? one thing is that the original routes should stay the same, admin.domain.com
should remain the same even though it gets the sub admin/
folder
I don't think .htaccess is the correct way to go here, unless you are on a shared hosting that doesn't allow you to create vhosts.
Here is an example vhost configuration:
<VirtualHost *:80>
DocumentRoot /var/www/public_html/front/
ServerName domain.com
FallbackResource /index.html
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/public_html/admin/
ServerName admin.domain.com
FallbackResource /index.html
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/api/public/
ServerName api.domain.com
FallbackResource /index.php
</VirtualHost>
The following will send all urls except what is a file and is excluded on top. Please test.
RewriteEngine On
RewriteBase /
#If static don't change anything and go direct
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule \.(ttf|svg|otf|png|gif|jpeg|jpg|ico|swf|css|js|html|htm|woff)((\?.*)|)$ - [L,NC]
RewriteCond %{HTTP_HOST} admin.domain.com
RewriteRule .* /admin/index.html [QSA,L,NC]
RewriteCond %{HTTP_HOST} domain.com
RewriteRule .* /front/index.html [QSA,L,NC]
RewriteCond %{HTTP_HOST} api.domain.com
RewriteRule .* /api/public/index.php [QSA,L,NC]