如何将我的所有路线都重定向到我的拉拉韦(Laravel)本地和同时居住的地方

问题描述 投票:0回答:1
我有一个laravel应用程序。当我dd($ request-> url())的任何请求都显示给我这样的网址屏幕中的http://example.test,但我想要的是我想要获得http://www.example.test

我已经尝试了一些诸如更改.htaccess文件和使用中间件的操作

我已经在中间件中完成了此操作

if (starts_with($request->header('host'), 'www.')) { $host = str_replace('www.', '', $request->header('host')); $request->headers->set('host', $host); return Redirect::to($request->fullUrl(), 301); } return $next($request);

但是仍然没有任何反应,在我的htaccess文件中,我做到了

RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

但还是一样。我想知道是否是因为我正在使用宅基,或者我的代码不正确注意:我也想在localhost上看到它,并且我正在使用无所事事的宅基laravel
php laravel vagrant homestead
1个回答
0
投票
尝试使用web.php文件

$req_path = trim($_SERVER['REQUEST_URI'], "/"); if (strpos($req_path,"www") ==false){ $req_path = trim($req_path,"/"); $url = "http://www.example.test/".$req_path; header("location:".$url, true,301); }

© www.soinside.com 2019 - 2024. All rights reserved.