我有一个新闻报道的网站。在这个,当我点击任何文章,然后它的地址看起来像news.php?id = 12但我希望它看起来像http://paritynews.com/news/YYYY/MM/DD/< 4位数> / headline /。 在这第一个节目的新闻类别然后文章的日期,然后文章编号,并在最后它显示帖子的标题。 这里是id链接http://www.monkks.com/part/parity-newsfinalpage/index.php 日Thnx。
答案 0 :(得分:0)
在这里,我发现了一个使用自定义URL的好文章。 http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/
您可以使用RewriteRule生成所需类型的网址。
答案 1 :(得分:0)
使用此.htaccess文件和$ _REQUEST变量。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
这是index.php文件。我已添加注释,您必须实际运行查询并处理结果。
//Routing...
$request = substr($_SERVER['REQUEST_URI'],1); //Out of the http://www.domain.com/blog/date -> blog/date is returned
$params = explode("/", $request); //Creates an array $params = ['blog','date'];
if($params[0] == ""){
//Default Route
$include_path = "default.html";
}else{
//If there is something in the URL that is useful
//Parse the rest of the url here
switch ($params[0]) {//The first varible Ex: 'blog' or 'news'
case 'news':
$article_date = join(array($params[1],$params[2],$params[3]),"-");//Formats the date for MySQL
$id_number = $params[4];
//Make sure to escpe the values here
$sql = "SELECT * FROM table_name WHERE (date_column = {$article_date} AND id = {$id_number}";
//Run the query with your perfered sql extension, mysqli or pdo
//Handle errors
$include_path = "news.php";
break;
case 'other':
$include_path = "something_else.php";
break;
}
}
if(isset($include_path)){
require($include_path);
}
?>