帮助处理.htaccess使我的网址漂亮

时间:2010-09-02 09:43:26

标签: php apache

我当前的网址如下所示。

  

http://example.com/news.php?id=25&cat=news&date=01092010&title=this-is-the-first-title

我想让它像

一样清洁
  

http://example.com/news/01092010/this-is-the-first-title

我只知道.htaccess如何与其指令的基本理解一起工作的基础,我该如何实现?

编辑:我不希望显示ID。

谢谢

1 个答案:

答案 0 :(得分:1)

RewriteRule ^([a-z]+)/([0-9]+)/([a-z-]+)$ /news.php?cat=$1&date=$2&title=$3

但请注意id未包含在此“漂亮网址”中!因此,您必须根据$_GET['date']$_GET['title']中的值,在news.php中手动查看(或直接获取新闻项)。

上述规则会将http://example.com/news/01092010/this-is-the-first-title表单上的请求转换为http://example.com/news.php?cat=news&date=01092010&title=this-is-the-first-title

相关问题