将PHP变量添加到URL中

时间:2017-01-14 18:05:18

标签: php .htaccess mod-rewrite

我不认为可以在.htaccess文件中添加PHP变量。除非我错了?

我的网站从数据库创建内容。我想更改网址以匹配正在显示的内容。

我想改变,

http://domain.com/products

http://domain.com/products/brand/partnumber

我有$ Brand和$ Partnumber

的php变量

如何根据正在显示的内容更改网址? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

在products / index.php下

<?php
 header("location: http://thisurl.com/products/".$brand."/".$partnumber);
?>

但是,您可以使用路由器,例如http://github.com/klein/klein.php

$klein->respond("/products/",function($request,$response){
   $response->redirect("/products/".$brand."/".$partnumber);
});
$klein->respond("/products/[:brand]/[:number]",function($request){
  return $request->brand." ".$request.number;
});

$klein->dispatch();