这是我的 SQL ( phpmyadmin ):
-----------------------------------------------
| id | label | link | parent | sort |
-----------------------------------------------
| 1 | A | a | 0 | 1 |
| 2 | B | b | 1 | 2 |
| 3 | C | c | 1 | 3 |
| 4 | D | d | 0 | 4 |
| 5 | E | e | 2 | 5 |
| 6 | F | f | 3 | 6 |
| 7 | G | g | 0 | 7 |
-----------------------------------------------
这是我的网址:
example.com/index.php?link=a
example.com/index.php?link=a/b
example.com/index.php?link=a/b/e
example.com/index.php?link=a/c
example.com/index.php?link=a/c/f
example.com/index.php?link=d
example.com/index.php?link=g
to
example.com/a
example.com/a/b
example.com/a/b/e
example.com/a/c
example.com/a/c/f
example.com/d
example.com/g
.htaccess
RewriteEngine On
DirectoryIndex index.php
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([a-zA-Z0-9-/]+)/$ index.php?link=$1
这是我的PHP:
if(!empty($_GET['link'])){
$url=mysqli_real_escape_string($db,$_GET['link']);
$query="SELECT * FROM menu WHERE link='$url'";
$result=mysqli_query($db,$query);
while($row=mysqli_fetch_array($result)){
echo $row['id'];
}
}
当我运行http://example.com/d/浏览器地址栏中的链接时,其输出如下: 4.
但是当我运行链接时http://example.com/a/b/e,它的屏幕变白或者输出不显示。
一只萌萌小番薯