2010-09-02 47 views
0

我目前的URL是这样的。帮助处理.htaccess使我的网址漂亮

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。

谢谢

+0

http://stackoverflow.com/search?q=pretty+url为什么不简单地帮助自己呢? – 2010-09-02 09:44:12

+0

'/ news/01092010/this-is-the-first-title'可以很容易地转换,但是你必须手动查找'id'(如果需要的话)。 – jensgram 2010-09-02 09:46:11

回答

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

+0

我不想显示ID。我该怎么做? – 2010-09-02 09:50:58

+0

您*可以*做的是将其添加到“漂亮的网址”,例如'http:// example.com/news/01092010/25-this-is-the-first-title'然后匹配它('^([az] +)/([0-9] +)/([ 0-9] +) - ([AZ - ] +)$')。或者,你必须做一个查找。 – jensgram 2010-09-02 09:53:52

+0

@Ibrahim,那么您将需要从数据库中查找标题/日期并获取匹配的记录,该记录应该是请求的文章。 – aularon 2010-09-02 09:54:49