Skip to content

Instantly share code, notes, and snippets.

@sdeering sdeering/.htaccess
Created Aug 11, 2014

Embed
What would you like to do?
Laravel 4 with AngularJS Architecture Solution .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
</IfModule>
@etiennemarais

This comment has been minimized.

Copy link

etiennemarais commented Aug 19, 2014

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

api
# Laravel api here
public/

public_html/
public_html/.htaccess
public_html/admin/index.html
public_html/front/index.html

How can I change the .htaccess to redirect so that the following is kept in tact?

api.domain.com > routes to /api/public
admin.domain.com > routes to /admin/index.html
domain.com > routes to /front/index.html

@sdeering

This comment has been minimized.

Copy link
Owner Author

sdeering commented Aug 20, 2014

Hi, the section of the htaccess above is used with the following structure: http://angularjs4u.com/concepts/laravel-4-angularjs-architecture/. 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
You can’t perform that action at this time.