你好,我已经创建了干净的网址 但是我想要一些东西获取动态网址并获取动态查询
我要链接 喜欢这个 http://localhost:8081/olshop/products/param/[类别]-[性别]
sample : http://localhost:8081/olshop/products/param/pants-m
with paging
http://localhost:8081/olshop/products/param/[category]-[gender]/paging
sample : http://localhost:8081/olshop/products/param/pants-m/1
但是这个用户可以像这样更改过滤器
http://localhost:8081/olshop/products/param/[category]
sample : http://localhost:8081/olshop/products/param/pants
with paging
http://localhost:8081/olshop/products/param/[category]/paging
sample : http://localhost:8081/olshop/products/param/pants/1
or
http://localhost:8081/olshop/products/param/[gender]
sample : http://localhost:8081/olshop/products/param/m
with paging
http://localhost:8081/olshop/products/param/[gender]/paging
sample : http://localhost:8081/olshop/products/param/m/1
or
http://localhost:8081/olshop/products/param/[gender]-[category]
sample : http://localhost:8081/olshop/products/param/m-pants
with paging
http://localhost:8081/olshop/products/param/[gender]-[category]/paging
sample : http://localhost:8081/olshop/products/param/m-pants/1
如何像这样技术??
我对我的代码和 .htaccess 的实现感到困惑
这是我目前的.htaccess。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule index$ index.php [L]
RewriteRule ^products/('d+)$ index.php?p=products&page=$1 [L]
RewriteRule ^products/param/([^/]+)/?$ index.php?p=products¶m=$1 [L]
RewriteRule ^products/param/(.*)'/('d+)$ index.php?p=products¶m=$1&page=$2 [L]
RewriteRule ^([^/.]+)/?$ index.php?p=$1 [QSA,L]
</IfModule>
这是我代码的一部分
<?php
if($_GET['param']!=NULL)
{
$query = mysqli_query($con,"select * from goods where category='".$_GET['param']."' and gender='".$_GET['param']."' order by date_publish DESC LIMIT $start, $limit");
}
else
{
$query = mysqli_query($con,"select * from goods order by date_publish DESC LIMIT $start, $limit");
}
?>
帮帮我谢谢
或者您有解决方案或其他?
您遇到的问题是您需要确定用户是否要求性别、类别或两者兼而有之。由于您的性别是通用且有限的;例如,m = 男性,f = 女性,a = 所有字符长,它们都是一个字符长,您最好只是解析该参数并查询页面(如果存在)。
您在这里面临的唯一真正的问题是您的性别/类别位置可以更改或逆转,这意味着如果两者都提供,那么您需要为两种类型查询两个部分,如果需要,那么您可以使用以下两种模式匹配来获取性别和类别,或者如果您决定格式,那么只需使用其中之一。
$param = 'pants-m'; //$_GET['param'];
if(preg_match('/^([m|f])(?:[-](.*))?$/i', $param, $match)) {
$gender = $match[1];
$category = isset($match[2]) ? $match[2] : null;
}
elseif(preg_match('/^([a-z0-9]{2,})(?:[-]([m|f]))?$/i', $param, $match)) {
$gender = isset($match[2]) ? $match[2] : null;
$category = $match[1];
}
var_dump($gender, $category);