【发布时间】:2017-06-11 02:22:41
【问题描述】:
我有以下问题,
我需要配置 Nginx,所以在任何 URL 用户访问时,它将保留 uri(例如 domain.com/some/url/),但仅传递给 laravel / 并让 Angular 处理路由。
Route::get('/', function(){
return view('index');
});
当访问 /api/{anything} 时,Laravel 将启动。
现在我从公用文件夹返回index.html,直到找到解决方案
这是我的配置:
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
我知道我可以制定如下路线:
Route::get('{anything?}', function(){
return view('index');
});
但是太宽泛了。
更新:
location / {
rewrite ^/(.*)$ / break;
index index.php;
try_files $uri $uri/ /index.php;
}
location /api {
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
【问题讨论】:
-
您是否正在寻找 NGINX 对所有请求执行 index.blade.php 脚本?如果是这样,您需要配置 fastcgi。
-
我有 fastcgi,问题不在于如何处理 php 文件,而在于如何从 laravel 始终返回
/路由但保留URI用于 angular -
您可以使用简单的重写规则剥离 URL:
rewrite ^/(.*)$ / last; -
@FaisalMemon 我应该把它放在哪里?我尝试过重定向周期。
-
对不起,把'last'改成'break'。它应该放在您希望它执行的位置。
标签: php angularjs laravel nginx laravel-5.3