我想知道是否可以重写一个看起来像这样的 url
www.example.com/item.php?id=1 to a www.example/item.php without the `?id=1`
请注意,1 代表产品 ID,因此它可能会更改为 2 或任何数字,具体取决于用户选择的产品
我当前的 htaccess
我的当前.htaccess
看起来像这样:
RewriteEngine on
RewriteBase /
RewriteRule ^item/(.*)$ test/main/pages/account/$1 [L] // **the item.php file is in the item folder**
ErrorDocument 404 /test/main/pages/general/index.php
Options -Indexes
AuthName "main"
我做到了
<?php
include('global.php'); ///database connection
function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(" ", $microTime);
$dec_hex = dechex($a_dec* 1000000);
$sec_hex = dechex($a_sec);
ensure_length($dec_hex, 5);
ensure_length($sec_hex, 6);
$guid = "";
$guid .= $dec_hex;
$guid .= create_guid_section(3);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section(6);
return $guid;
}
$stmt = $conn->prepare("INSERT INTO `Product (`pid`, `Guid`, `price`) VALUES
(13, '".$guid."', 13)");
$stmt->execute();
?>
我也是使用 PDO 做的,因为我不是 mysql 的忠实粉丝