在 PHP 中使用路由时在 URL 中传递参数

我在 php 中实现了路由,一切正常,除非我尝试像这样在 url 上发送数据:


http://localhost/search/?sprefix=all

有时它看起来像这样:


http://localhost/search/?sprefix=Sippers%20&%20Mugs+sprefix_sub=children%20mugs

这是我的路线


<?php


$request = $_SERVER['REQUEST_URI'];

switch ($request) {

    case '/search/':

        require __DIR__ . '/views/Product/Search/Search.php';

        break;

}

?>

和.htaccess文件


RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ index.php [QSA,L]

有人可以帮我做到这一点吗?


月关宝盒
浏览 160回答 1
1回答

qq_遁去的一_1

使用$_GET[]orparse_url()来解决你的问题
打开App,查看更多内容
随时随地看视频慕课网APP