我想使博客网址的PHP seo友好,不使用鼻涕虫


I want to make Blog Url of PHP seo friendly without using slug

我正在开发一个自定义cms的核心php网站。我面临的问题,而使博客url的seo友好。

我的Url是这种类型,我希望Url是这样的websitename/博客/标题如果我通过htaccess文件修复它,那将是静态的,因为我想要一个单一的功能,为未来的博客文章以及工作。所以请帮我解决这个问题

使用htaccess

将特定博客标题设置为$_GET
RewriteRule    ^blog/([A-Za-z0-9-]+)/?$    /blogs.php?blog=$1    [NC,L]

那么你可以从博客的id或标题中打印出博客

设置好之后,您需要在blogpost.php脚本中从数据库的blog表中获取$_GET数据,如下所示:

$sql ="SELECT * FROM blog_table WHERE title = ".$_GET['blog']." LIMIT 1";
$blog = mysqli_fetch_array(mysqli_query($sql));
echo '<h1>'.$blog['title'].'</h1>';
echo '<p>'.$blog['content'].'</p>';

显然需要考虑安全性,准备好的语句会更好。

你可以试试:-

RewriteEngine On
RewriteBase /
RewriteRule ^blogpost.php/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]
# or slightly nicer would be to remove the `.php` thus:-
RewriteRule ^blogpost/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]