[英]Blog feed/archive pages using PHP/SQL
I have been asked to create a website and wanted to design it so that the user may add new blog posts to a news feed. 我被要求创建一个网站,并希望对其进行设计,以便用户可以将新的博客文章添加到新闻提要中。 I've tried this and successfully created a very simple blogging feature which adds/reads entries in a sql database. 我已经尝试过并成功创建了一个非常简单的博客功能,该功能可以在sql数据库中添加/读取条目。
However I want to dynamically create new webpages for each blog entry that is added by the user. 但是,我想为用户添加的每个博客条目动态创建新的网页。 How would I go about this? 我将如何处理? I am new to Php/Sql and so I am unsure of where to start. 我是Php / Sql的新手,所以我不确定从哪里开始。 Any pointers in the right direction would be greatly appreciated. 朝正确方向的任何指针将不胜感激。
As for an example of what im after, see: http://kingslandprimaryschool.co.uk/ 有关即时消息的示例,请参见: http : //kingslandprimaryschool.co.uk/
Thanks 谢谢
The solution is to hire an army of employees, who manually create hundreds of scripts. 解决方案是雇用一批员工,他们手动创建数百个脚本。 A lot of work, but what else can you do? 很多工作,但是您还能做什么? Nah, just kidding. 不,开玩笑。
The trick is not to create a new file for every blog page, you just have to change the routing. 诀窍是不必为每个博客页面都创建一个新文件,而只需更改路由。 Start by creating a blogging system which works through consistent URL's, such as blog.php?p=home
. 首先创建一个博客系统,该系统可以通过一致的URL进行工作,例如blog.php?p=home
。 When you've finished, create a .htaccess file which routes certain requests to that page. 完成后,创建一个.htaccess文件,该文件将某些请求路由到该页面。 For example, if you would want an URL like my.site/home
to load blog.php?p=home
you would need the following .htaccess script: 例如,如果您希望像my.site/home
这样的URL加载blog.php?p=home
,则需要以下.htaccess脚本:
<IfModule mod_rewrite.c>
RewriteEngine On
# Allow existing directories and files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Route the request
RewriteRule ^(.*)$ blog.php\?p=$1 [QSA]
</IfModule>
This would first check whether a file exists at the requested URL. 这将首先检查在请求的URL是否存在文件。 If it does, it shows that file. 如果是这样,它将显示该文件。 Otherwise, blog.php?p=myPath
is opened. 否则,将打开blog.php?p=myPath
。 The [QSA]
tag after the redirect means that everything after the question mark is passed on to the script you redirect to, so if you would go to my.site/home?day=wednesday
the page blog.php?p=home&day=wednesday
would be loaded. 重定向后的[QSA]
标签表示问号后的所有内容都将传递到您重定向到的脚本,因此,如果您要转到my.site/home?day=wednesday
页面blog.php?p=home&day=wednesday
将加载。
If you need more help, feel free to ask any question. 如果您需要更多帮助,请随时提出任何问题。 Alternatively, you can just Google "htaccess mod_rewrite" or "PHP pretty url" for more information. 另外,您也可以只使用Google“ htaccess mod_rewrite”或“ PHP pretty url”以获取更多信息。 Hope this was of help! 希望这对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.