We are using Laravel 5 and have a route that handles all requests:
Route::any('{all}', 'AllController')
->where('all', '.*');
However this is causing one challenge: it redirects everything including images, JS and CSS.
We would like assets (static content) to be handled by the web server and Laravel to only handle dynamic content. We tried this:
Route::any('{all}', 'AllController')
->where('all', '.*')->where('all', !=, 'assets/.*');
But it gives syntax error unexpected '!=' (T_IS_NOT_EQUAL)
.
How can we construct a route that handles everything except assets (static content)?
Edit: .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
It looks like you have trouble with web server config.. Laravel will handle route only if requested file doesn't exist. In other case web server will return your .css .js without Laravel. For Apache this rules looks like
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
UPD: In any case you can using regexp for this
Route::any('{all}', 'MyBar@index')->where('all','^((?!assets).)*?');