将GET参数转换为友好URL

时间:2017-09-07 12:27:16

标签: .htaccess

我有一个网址:www.example.co.uk/news-and-views/article.php?Id=name-of-article

news-and-views的索引页面只是吐出所有新闻文章和一个URL来查看文章(上面的那个)

基本上SELECT * FROM news

而不是news-and-views/article.php?Id=name-of-article我想删除article.php?Id=,以便网址只是news-and-views/name-of-article

我知道在.htaccess文件中你可以这样做:

RewriteRule /(.*)/$ article.php?Id=$1

但这似乎不起作用?

我是在正确的轨道上吗?

1 个答案:

答案 0 :(得分:0)

使用此规则......

RewriteRule ^news-and-views/(.+) /news-and-views/article.php?Id=$1

...将以您描述的方式屏蔽网址。

所以转到http://www.example.co.uk/news-and-views/test会在幕后调用http://www.example.co.uk/news-and-views/article.php?Id=test