【发布时间】:2011-11-24 03:10:15
【问题描述】:
我有这个网站 http://www.finalyearondesk.com 。我的博客文章链接是这样设置的.. http://www.finalyearondesk.com/index.php?id=28 。我希望它像这样设置... finalyearondesk.com/2011/09/22/how-to-recover-ubuntu-after-it-is-crashed/ 。
我正在使用以下函数来获取这些帖子...
function get_content($id = '') {
if($id != ""):
$id = mysql_real_escape_string($id);
$sql = "SELECT * from cms_content WHERE id = '$id'";
$return = '<p><a href="http://www.finalyearondesk.com/">Go back to Home page</a></p>';
echo $return;
else:
$sql = "select * from cms_content ORDER BY id DESC";
endif;
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) != 0):
while($row = mysql_fetch_assoc($res)) {
echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>';
echo '<p>' . "By: " . '<font color="orange">' . $row['author'] . '</font>' . ", Posted on: " . $row['date'] . '<p>';
echo '<p>' . $row['body'] . '</p><br />';
}
else:
echo '<p>We are really very sorry, this page does not exist!</p>';
endif;
}
我正在使用此代码在我的 index.php 页面上显示它...
<?php
if (isset($_GET['id'])) :
$obj -> get_content($_GET['id']);
else :
$obj -> get_content_summary();
endif;
?>
任何建议如何做到这一点?我们可以通过使用 .htaccess 来做到这一点吗?
【问题讨论】:
-
如果您的服务器上启用了 mod_rewrite,您可以在 .htaccess 中使用它。
-
但这只是一篇文章?或者告诉我该怎么做? wordpress 是怎么做到的?
-
我从未使用过wordpress,所以我不知道。你熟悉正则表达式吗?您可以使用带有正则表达式捕获组的重写规则来执行此操作。
-
看到这个,我想达到这样的目标askapache.com/htaccess/…
-
您也可以考虑查看webmasters.stackexchange.com