Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Finally I found a working solution, perfect in my scenario, which does not require a subdomain. In this case Laravel acts exclusively as a RESTful web service, no server side views or templates: the presentation layer is completely demanded to AngularJS.</p> <p>Let's say I have two completely decoupled applications (FE e WS) inside the same root folder:</p> <pre><code>root |__fe |__ws </code></pre> <p>I modified virtual host settings under Apache httpd-vhosts.conf file the following way:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerName myapp.com DocumentRoot "\www\root\fe" alias /ws "\www\root\ws\public" &lt;Directory "\www\root\ws\public"&gt; Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny Allow from all &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>I then added "RewriteBase /ws" into my laravel/public/.htacces file:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; Options -MultiViews RewriteEngine On RewriteBase /ws RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [NC,L] &lt;/IfModule&gt; </code></pre> <p>This way I can write in the browser (for instance):</p> <pre><code>http://myapp.com (AngularJS client side root) http://myapp.com/ws/users (RESTful service endpoint for "users") </code></pre> <p>And then define a client side, AngularJS routing the following way:</p> <pre><code>app.config(function($routeProvider) { $routeProvider .when('/', {controller: 'HomeController', templateUrl: 'templates/home.html'}) .when('/users', {controller: 'UsersController', templateUrl: 'templates/users.html'}) .otherwise({redirectTo: '/'}); }); </code></pre> <p>Linking it to a RESTful resource this way:</p> <pre><code>app.factory('User', function($resource) { return $resource('http://myapp.com/ws/users'); }); app.controller('UsersController', function($scope, User) { $scope.title = "Users"; $scope.users = User.query(); }); </code></pre> <p>I enabled HTML5 history API, adding this line to configure my Angular application:</p> <pre><code>$locationProvider.html5Mode(true); </code></pre> <p>together with (inside index.html head section):</p> <pre><code>&lt;base href="/" /&gt; &lt;meta name="fragment" content="!" /&gt; </code></pre> <p>So the last requirement to solve problems like browser page refresh, deep linking, or direct page bookmark, is to add a .htaccess file in the root of the folder which contains the Angular application:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html [NC,L] &lt;/IfModule&gt; </code></pre> <p>Hope it helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload