使用 PHP 创建动态 URL

Creating dynamic URL's with PHP

)

我正在创建动态事件创建应用程序,但在为事件创建动态网页时遇到了 运行 问题。

我的 .htaccess 看起来像

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f  
RewriteRule ^([^\.]+)$ .php [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^\.]+)$ table.php?event= [L]

我的table.php看起来像

$getEvent = explode("/",$_SERVER['REQUEST_URI']);
print_r($getEvent);
$conn = new mysqli($host, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}   
$result = $conn->query("SELECT * FROM event where link='$getEvent[4]'");
echo $getEvent[4];  

页面结构如下:

http://page.ex/~name.name/reg/

当我尝试进入时

http://page.ex/~name.name/reg/joulupidu

尽管 "joulupidu" 在事件 table 中,但我得到 404。我不知道去哪里看,因为我以前没有做过太多这类事情。

谢谢, 周!

你的 .htaccess 应该是这样的

RewriteEngine On
RewriteRule ^([^/.]+)/reg/([^/.]+)?$ reg/table.php?event=&%{QUERY_STRING}

你的 table.php 文件应该是这样的

$getEvent = $_REQUEST['event'];
//print_r($getEvent);
$conn = new mysqli($host, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}   
$result = $conn->query("SELECT * FROM event where link='$getEvent'");
echo $getEvent;