带有.htaccess和php的url的子目录

lvmkulzt  于 2022-11-16  发布在  PHP
关注(0)|答案(1)|浏览(155)

我用了这个
这是我的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,它的屏幕变成白色或输出不显示.

dxpyg8gm

dxpyg8gm1#

您正在将其重写为index.php?link=a/B/e

相关问题