我已经尝试了一些诸如更改.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
$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);
}