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

问题描述 投票:0回答:1

我在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]

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

提前感谢

php routing
1个回答
0
投票

使用$_GET[]parse_url()解决您的问题

© www.soinside.com 2019 - 2024. All rights reserved.