Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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_Url_Rewrite - Fatal编程技术网

Php 以新的方式重写URL

Php 以新的方式重写URL,php,.htaccess,url,rewrite,Php,.htaccess,Url,Rewrite,我有一个产品库。而每个产品的详细页面链接为: <a href="http://productgallery.com/product.php?productid=<?php echo recordset['product_id'];?>"><?php echo recordset['product_name'];?></a> 等等 假设产品id“008”的名称是“棒球帽”,它也在数据库中。 现在,我想将url重写如下: http://product

我有一个产品库。而每个产品的详细页面链接为:

<a href="http://productgallery.com/product.php?productid=<?php echo recordset['product_id'];?>"><?php echo recordset['product_name'];?></a>
等等

假设产品id“008”的名称是“棒球帽”,它也在数据库中。 现在,我想将url重写如下:

http://productgallery.com/product/baseball-cap
如何使用[.htaccess]?请帮帮我


请注意,我不想去

http://productgallery.com/product/008
http://productgallery.com/product/baseball-cap
当链接为:

http://productgallery.com/product.php?productid=008
而且我有限制只将“productid”作为GET参数发送。 但是我想像你一样去

http://productgallery.com/product/008
http://productgallery.com/product/baseball-cap
现在,产品名称“棒球帽”来自数据库


这就是我要问的。有人能帮我吗。

您可以在产品标题中添加产品id。例如,您可以使用以下模式:

http://productgallery.com/product/008-baseball-cap
并按如下方式更改访问权限:

RewriteEngine On
RewriteRule ^product\/([^\\/]*)-([^\\/]*)$ product.php?productid=$1 [NC,QSA]