简体   繁体   English

将PHP变量添加到URL

[英]Adding a PHP variable into the URL

I don't think it is possible to add a PHP variable into the .htaccess file. 我认为不可能将PHP变量添加到.htaccess文件中。 Unless I am wrong? 除非我错了?

My website creates content from a data base. 我的网站从数据库创建内容。 I would like to change the URL to match what is being show. 我想更改URL以匹配正在显示的内容。

I want to change, 我想改变,

http://domain.com/products

to

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

I have php variables for $Brand and $Partnumber 我有$ Brand和$ Partnumber的php变量

How do I change the URL based on what is being show? 如何根据显示的内容更改URL? Thanks in advance. 提前致谢。

Under products/index.php 在products / index.php下

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

However, you may use a router, sth like http://github.com/klein/klein.php : 但是,您可以使用路由器,例如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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM