简体   繁体   English

页面形式MySQL数据库上的URL标题调用

[英]URL Title call on Page form MySQL Database

I created a blog with fields are blog_title and blog_contents these data are stored into mysql database and i want to display this blog post on www.example.com/blog page with specific url blog_title 我创建了一个博客,其中的字段是blog_titleblog_contents,这些数据存储在mysql数据库中,我希望在www.example.com/blog页面上显示此博客文章,其中包含特定网址blog_title

eg: www.example.com/blog/blog title 例如: www.example.com/blog/blog title

Then particular title of the blog should be fetch form database and displayed over the page. 然后博客的特定标题应该是获取表单数据库并显示在页面上。

How can we achieve this? 我们怎样才能做到这一点?

Yes. 是。 You need to have a look at the "URL Rewrite". 你需要看一下“URL Rewrite”。

Here's a link: URL rewrite 这是一个链接: URL重写

Hope this helps :) 希望这可以帮助 :)

Some quick guidelines how I would do it: 一些快速指导我将如何做到:

Start from the url www.example.com/blog.php?id=1 从网址www.example.com/blog.php?id=1开始

You get the id from the url: 你从网址获得了id:

$blogId = $_GET['id']

Then your SQL query: 然后你的SQL查询:

SELECT * FROM blogs where id = $blogId

Build your page with the result of this query. 使用此查询的结果构建您的页面。

To get the url showed like you want: URL Rewriting 要显示您想要的网址URL重写

You have o search for two things: 你有搜索两件事:

  1. mod_rewrite / url rewriting, because on your server won't be a folder called /blog/this-is-my-blog-title (mod_rewrite will redirect that url to your eg index.php which does the rest) mod_rewrite / url重写,因为在你的服务器上不会是一个名为/ blog / this-is-my-blog-title的文件夹(mod_rewrite会将那个url重定向到你的例如index.php,剩下的就是这个)

  2. you need that index.php which does the rest for you -> converting an url-blog-title into your real blog title in your database to fetch its content. 你需要index.php为你完成其余工作 - >将url-blog-title转换为数据库中的真实博客标题以获取其内容。 The most easiest way is by using urlencode() , but then it will look really ugly. 最简单的方法是使用urlencode() ,但它看起来真的很难看。 You need some script / code which converts whitespaces into hyphen (-) There are also some tutorials out there, just search for "seo friendly blog urls" for example. 你需要一些将空格转换为连字符的脚本/代码( - )还有一些教程,例如搜索“seo friendly blog urls”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM