Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP变量添加到URL中_Php_.htaccess_Mod Rewrite - Fatal编程技术网

将PHP变量添加到URL中

将PHP变量添加到URL中,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我认为不可能在.htaccess文件中添加PHP变量。除非我错了 我的网站从数据库创建内容。我想更改URL以匹配正在显示的内容 我想改变 http://domain.com/products 到 我有$Brand和$Partnumber的php变量 如何根据正在显示的内容更改URL? 提前感谢。在products/index.php下 <?php header("location: http://thisurl.com/products/".$brand."/".$partnumber

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

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

我想改变

http://domain.com/products

我有$Brand和$Partnumber的php变量

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

在products/index.php下

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

更改URL是什么意思?比如,将客户端重定向到新页面?对于SEO,我认为最好每个产品都有自己的URL。我有一个包含所有产品信息的数据库。我动态创建产品页面,只是尝试更新URL,使其与所显示的内容相匹配。我一直在尝试您的顶级示例。我一直在运行一个无限循环。但我认为这是我需要走的方向。@brendan:下面的示例甚至更好,因为您可以轻松地扩展/实现它。Thazs我是如何完成我所有的项目的
<?php
 header("location: http://thisurl.com/products/".$brand."/".$partnumber);
?>
$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();