无法在laravel web.php中加载45k根url



我的客户在以前的网站上有7896页旧网站网址,如:www.domain.com/{url}

现在客户端想要制作新的网站,但他需要相同的url结构作为旧的(www.domain.com/{url})

客户端有大约45000个博客文章在不同的类别&这需要从laravel管理面板管理。

如果我需要这样做,那么我在根域中有45k的url,比如(www.domain.com/{url}),这里的问题是网站中有新的发展,也有像

这样的路由(www.domain.com/category/{cat_url})(www.domain.com/tags/{cat_url})

我有45k的博客网址在web.php文件

www.domain.com/{url}

问题列表
  • 内存限制问题
  • 缓慢的性能问题(4.5秒加载页面,在每个请求加载45k url在路由)

现在在aws服务器中,我面临着内存超时的问题,因为我在根目录中有大量的URL被加载到内存中。

错误信息:

local.ERROR: Out of memory (allocated 38469632) (tried to allocate 3170560 bytes) {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Out of memory (allocated 38469632) (tried to allocate 3170560 bytes) at /domain.com/routes/dynamic_blog_routes.php:33026)
[stacktrace]
#0 {main}
"} 
  • 我不能改变URL结构,因为seo已经很好了

有什么办法可以解决这个问题吗?而不是在web。php中只有一个函数或方法的45k url我们可以使用它吗?

请分享你的解决方案或指导我。

我的web.php文件像。

<?php
Route::get('test-blog', 'FrontBlogController@blog_details');
Route::get('hello-world', 'FrontBlogController@blog_details');
--- 45k routes like this ---

@ vsal hseynli

根据你的评论,我已经解决了这个问题。

我的web.php文件

<?php
Route::get('category/{any}', 'FrontBlogController@cat_details');
Route::get('tags/{any}', 'FrontBlogController@tag_details');
Route::get('{any}', 'FrontBlogController@blog_details');
?>

我的BlogController.php文件

class BlogController extends Controller
{
public function blog_details(Request $request)
{
$urlSegment = $request->segment(1);
if(empty($urlSegment)){
abort(404);
}
$blog = Blog::where("slug", "=", $urlSegment)->first();
dd($blog);
}
}

我可以访问我所有的博客路由以及其他不属于博客的url。