Laravel 5.4 上的 SEO

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43326769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:45:59  来源:igfitidea点击:

SEO on Laravel 5.4

laravelseokeywordmeta-tagslaravel-5.4

提问by A.n1014

I am implementing a website for generating analytics for various institutes in the USA. I now need to implement SEO on my website. I have edited all the URL's to have them SEO friendly. Now my question is, how to find the keywords,meta tags for my laravel website and how to include them in my website. On my home page ? or any where else ?

我正在实施一个网站,用于为美国的各个机构生成分析。我现在需要在我的网站上实施 SEO。我已经编辑了所有的 URL,让它们对 SEO 友好。现在我的问题是,如何为我的 Laravel 网站找到关键字、元标记以及如何将它们包含在我的网站中。在我的主页上?或其他任何地方?

回答by p01ymath

Create a layout.blade.phpand @yieldthe section named title and meta. When the user requests the page, it will pass through controller from which you can fetch the Title and meta description tag from your post_metatable or some table in which you store your Meta description.

I am working on one CMS based on Laravel and I am doing same. To make it easy for you to understand, here is the simple example!

创建 alayout.blade.php@yield名为 的部分title and meta。当用户请求页面时,它将通过控制器,您可以从中获取标题和元描述标签从您的post_meta表或存储元描述的某个表中。

我正在开发一个基于 Laravel 的 CMS,我也在做同样的事情。为了方便大家理解,这里举个简单的例子!

Example Route.php(Your User Friendly URLs)

Route.php 示例(您的用户友好 URL)

Route::get("page/{page_id}","PageController@show");


Example Controller Function


示例控制器功能

public function show($page_id)
{
    // Fetching Meta Tag Content from Table and Passing it to View
    $page_meta = Page::getMeta($page_id);

    return view('pages.show')->with('meta_description',$page_meta);
}


Example Layout.blade.php(Your Layout file)


示例 Layout.blade.php(您的布局文件)

<html>
    <head>
        @yield('title_and_meta')
    </head>
    <body>
        @yield('body_content')
    </body>
</html>


Example Page view(Your view file that will be shown to user!)


示例页面视图(您的视图文件将显示给用户!)

@extends('your_layout')

@section('title_and_meta')
    <title>Your Page title</title>
    <meta name="description" content="{{ $meta_description }}" />
@endsection

@section('body_content')
    // Content here!
@endsection

Surely, you can use the Variables Passed from Controller in the views! You can pass the Array Containing Title, Meta Description, Meta Author, Meta Keywords (Deprecated) and more Page meta Stuff and show it in the view!

This is how you make your Laravel Project SEO Friendly. My Content Management System is not yet Ready otherwise I can give you the URL of my GitHub Project from which you can understand it better!

Hope this helps! Let me know if you have any more Questions!

当然,您可以在视图中使用从控制器传递的变量!您可以传递包含标题、元描述、元作者、元关键字(已弃用)和更多页面元资料的数组并在视图中显示!

这就是你如何让你的 Laravel 项目 SEO 友好。我的内容管理系统还没有准备好,否则我可以给你我的 GitHub 项目的 URL,从中你可以更好地理解它!

希望这可以帮助!如果您还有其他问题,请告诉我!