首页 > 解决方案 > 干净 URL 的 .htaccess 重写规则不起作用

问题描述

htaccess 重写规则,我遇到了麻烦。当我在 URL (/page/1) 中输入正确的 slug 地址时,我得到未定义的变量错误。非常感谢任何帮助。

HTACCESS

RewriteRule ^page/([0-9a-zA-Z]+)$ page.php?id?=$1 [NC,L]

PHP代码:

<?php
require_once("db.php");
$sql = $conn->prepare("SELECT meta_desc, title, content, url_slug  FROM tbl_emp_details WHERE id=?");
    $sql->bind_param("i",$_GET["id"]);          
    $sql->execute();
    $result = $sql->get_result();
    if ($result->num_rows > 0) {        
        $row = $result->fetch_assoc();
    }
    $conn->close();
?>
<html lang="en">
<head>
  <meta charset="utf-8">

  <title>The HTML5 Herald</title>
  <meta name="description" content="<?php echo $row["meta_desc"]?>">
  <meta name="author" content="SitePoint">

  <link rel="stylesheet" href="css/styles.css?v=1.0">

</head>

<body>
  <h1><?php echo $row["title"]?></h1>
  <div class="content">
  <?php echo $row["content"]?>
  </div>

我认为的错误是因为我没有把它放在 page.php 中,但我不知道如何实现它。

标签: php.htaccessurl-rewriting

解决方案


推荐阅读