Skip to content

Instantly share code, notes, and snippets.

Created Aug 11, 2014
What would you like to do?
Laravel 4 with AngularJS Architecture Solution .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
RewriteEngine On
# Redirect root requests
RewriteCond %{REQUEST_URI} ^/$
RewriteRule !^/ /back-end/public%{REQUEST_URI} [L]
# Redirect API requests
RewriteCond %{REQUEST_URI} ^/api/(.*)$
RewriteRule ^api/(.*)$ /back-end/public/%{REQUEST_URI} [L]
# Redirect all other requests
RewriteRule (.*)\.(gif|jpg|jpeg|png|ico|css|js|woff|ttf|svg|eot|otf|json|html|pdf|swf)$ /front-end/dist/$1.$2 [R,L]
#RewriteRule ^ /front-end/dist/$1 [R=301,NC,L]
# html5 pushstate (history) support
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
Copy link

etiennemarais commented Aug 19, 2014

I am having trouble getting this to work. My structure is as follows:

# Laravel api here


How can I change the .htaccess to redirect so that the following is kept in tact? > routes to /api/public > routes to /admin/index.html > routes to /front/index.html

Copy link

sdeering commented Aug 20, 2014

Hi, the section of the htaccess above is used with the following structure: Have 3 domains (main and 2 sub domains) you'll need 3 main rules in your htaccess to catch each case. Something like this (untested):

Redirect root requests

RewriteCond %{REQUEST_URI} ^www./$
RewriteRule !^/ /front/index.html%{REQUEST_URI} [L]

Redirect api requests

RewriteCond %{REQUEST_URI} ^api./$
RewriteRule !^/ /api/public%{REQUEST_URI} [L]

Redirect admin requests

RewriteCond %{REQUEST_URI} ^admin./$
RewriteRule !^/ /admin/index.html%{REQUEST_URI} [L]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment