Created
August 11, 2014 03:33
-
-
Save sdeering/8bb05352644dad2078bc to your computer and use it in GitHub Desktop.
Laravel 4 with AngularJS Architecture Solution .htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
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