1

我先描述一下我的情况:

我有一个博客网站,博客条目存储在 MySQL 数据库中,然后在用户访问该网站时加载。每个博客文章都有可用于搜索博客文章的标签。我希望用户在使用 Google 等搜索引擎搜索帖子标签或标题中的相关字词时,能够将我的个人博客帖子作为结果。

例如,如果我有一个标题为“在 URL 中包含博客文章标题以进行搜索引擎优化?”的帖子,并且用户搜索“url seo 中的博客文章标题”之类的内容,那么我希望我的帖子应该显示作为结果之一(例如,当您在 Google 上搜索编程问题时,很多结果都来自 Stackoverflow)。

我猜我必须实现一个系统,在其中创建一个名为 post.php 的动态 php 页面,在该页面中,该页面用于显示单个博客文章,其标题包含在 url 中。此外,将帖子标签作为此页面的元关键字包含在内会很好。但我不想在我的服务器上拥有每个博客文章的静态页面,这样我就可以在 url 中包含标题。如果您查看 stackoverflow 的操作方式,他们会有单独的帖子链接到 url,其中帖子的标题包含在 url 本身中。我想要类似的东西。所以我最后改写的问题是:

1)在 URL 中包含帖子标题对 SEO 有好处吗?

2)使用从 MySQL 加载博客文章数据的动态页面是否对 SEO 不利,因为数据实际上并没有出现在网站上?

3)如何创建一个动态页面,用于在单击单个博客文章时显示它们并且在 URL 中有博客文章标题(类似于 Stackoverflow 所做的)?奖励:如果它可以将帖子标签作为元关键字,那就太棒了!

4

2 回答 2

2

使用robots.txt链接到站点地图,您可以在其中列出所有网址。谷歌会找到它。

此外,但不是至关重要的:使用.htaccess神奇地将 php-url-crap 转换为 domain.ext/category/post-id.html 或任何其他SEO 友好的 URL

更新:嗯,我一般不信任 XML。我所有的站点地图都是 php 生成的 html 文件,它们工作得很好。

  1. URL结构对SEO很重要。
  2. 那没关系。看看 Wordpress、Joomla、Drupal……同样的原理。
  3. 您有一些 page.php 文件,在交付 html 之前,执行SQL 查询并仅选择该 URL 的数据,然后将其插入到 html 中,每个用户输入不同的 url,将看到不同的内容。

我建议您花一些时间观看或阅读有关“PHP MYSQL 初学者 CMS”主题的教程

于 2012-08-11T20:15:50.607 回答
1

我会使用这样的东西:

<!DOCTYPE HTML>
<!--
<?php
if(!isset($_GET['id']) && empty(trim($_GET['id']))) die('No post number specified!');
$conn = mysqli_connect('localhost', 'username', 'password', 'blog_db') or die('MySQL connection failed!');
$id = mysqli_real_escape_string($conn, preg_replace('/[^0-9]/', '', $_GET['id'])
$query = "SELECT * FROM `posts` WHERE `id` = '$id'";
$result = mysqli_query($conn, $query) or die('MySQL query failed!');
$post = mysqli_fetch_assoc($result) or die('Fetching content failed!');
$title = $post['title'];
$content = $post['content'];
$tags = explode(',', $post['tags']);
$author = $post['author'];
$time = $post['time'];
?>
-->
<html lang="en-US">
<head>
    <meta charset="UTF-8" />
    <title><?php echo htmlentities($title); ?> &mdash; By Blog</title>
    <meta name="keywords" content="<?php echo implode(',', htmlentities($tags)); ?>" />
</head>
<body>
    <div id="post">
        <div id="post-content">
<?php echo htmlentities($post); ?>
        </div>
        <div id="post-tags">
            <ul id="tags">
<?php foreach($tags as $tag) { ?>
                <li>
                    <a href="/tagged/<?php echo urlencode($tag); ?>"><?php echo htmlentities($tag) ?></a>
                </li>
<?php } ?>
            </ul>
        </div>
        <div id="author">posted by <a href="/author/<?php echo urlencode($author); ?>"><?php echo htmlentities($author); ?></a></div>
    </div>
</body>
</html>

您可能希望研究 URL 重写(查看此 URL:标题可见,但实际文件不存在),这将使其对搜索引擎更加友好。

此外,为访问者提供站点地图也很好,因为搜索引擎也会跟踪那里的链接。

于 2012-08-11T20:38:05.253 回答